JSON to Dart

Converts a JSON object into Dart model classes with typed final fields and a named-parameter constructor ready for Flutter projects. You can independently toggle the fromJson factory constructor and the toJson serialisation method, and nested objects automatically generate their own classes. The conversion is fully browser-based, producing a .dart file you can copy or download instantly.

Input

JSON

Class Name

Methods

Output

Dart Code

What is JSON to Dart Converter?

Flutter app development involves a lot of JSON deserialisation — API responses, Firebase documents, local storage data. The boilerplate is always the same: a class with final fields, a fromJson factory constructor, and a toJson method. Writing this for every API endpoint by hand is the kind of work that gets automated. Paste your JSON here and get a complete Dart class with null-safe types, a fromJson factory that handles nested objects recursively, and a toJson method for serialising back to a Map. For projects using build_runner and json_serializable, enable the JsonSerializable annotation output. Add a copyWith method for Riverpod, Bloc, or Provider state management patterns. The generated code targets Dart 2.12+ null safety and is immediately compatible with the http and dio packages used in production Flutter apps.

How to Use

  1. 1

    Paste Your JSON

    Paste a JSON object or array into the editor. Null values produce nullable types (String?); arrays produce List<T>. For Flutter apps, use a real API response sample for accurate type inference.

  2. 2

    Configure Dart Class Options

    Set the root class name, choose whether to generate fromJson/toJson methods, enable copyWith support, and optionally add json_serializable annotations for code generation with build_runner.

  3. 3

    Generate Dart Classes

    Click "Generate Dart". The tool produces class definitions with named required parameters, fromJson factory constructors, toJson methods, and nested class definitions for nested objects.

  4. 4

    Add to Your Flutter or Dart Project

    Copy the generated classes into a models/ directory in your Flutter project. Use MyClass.fromJson(jsonMap) to deserialise API responses from http or dio, and .toJson() to serialise back for PUT/POST requests.

Common Use Cases

Flutter App Models

Generate Dart model classes from REST API response JSON for Flutter apps, with fromJson() factory constructors and toJson() methods for use with http or dio packages.

Firebase Firestore Models

Create Dart data classes from your Firestore document JSON structure to ensure type-safe reads and writes in Flutter apps using the cloud_firestore package.

API Client Code Generation

Scaffold Dart response model classes from API documentation sample JSON to build typed API clients without manually writing every field declaration and serialisation method.

State Management Models

Generate immutable Dart classes from JSON state snapshots for use with Riverpod, Bloc, or Provider state management, enabling copyWith patterns and type-safe state updates.

Conversion Examples

JSON Object → Dart Class with fromJson/toJson

A JSON object generates a Dart class with factory constructor and serialisation methods.

Input JSON

{
  "id": 1,
  "name": "Alice",
  "email": "alice@example.com",
  "isPremium": true
}

Output CSV

class Root {
  final int id;
  final String name;
  final String email;
  final bool isPremium;

  Root({required this.id, required this.name, required this.email, required this.isPremium});

  factory Root.fromJson(Map<String, dynamic> json) => Root(
    id: json['id'],
    name: json['name'],
    email: json['email'],
    isPremium: json['isPremium'],
  );

  Map<String, dynamic> toJson() => {'id': id, 'name': name, 'email': email, 'isPremium': isPremium};
}

Nested JSON → Nested Dart Classes

Nested objects generate separate Dart classes with typed cross-references.

Input JSON

{
  "product": {"id": 1, "name": "Widget"},
  "quantity": 5,
  "total": 49.95
}

Output CSV

class Product {
  final int id;
  final String name;
  Product({required this.id, required this.name});
  factory Product.fromJson(Map<String, dynamic> json) => Product(id: json['id'], name: json['name']);
}

class Root {
  final Product product;
  final int quantity;
  final double total;
  Root({required this.product, required this.quantity, required this.total});
  factory Root.fromJson(Map<String, dynamic> json) => Root(
    product: Product.fromJson(json['product']),
    quantity: json['quantity'],
    total: json['total'].toDouble(),
  );
}

Frequently Asked Questions