JustRandom

JSON to Dart Model Converter

Generate Flutter-ready Dart models with fromJson and toJson.

Generate Dart / Flutter from JSON

Paste sample JSON and generate Dart / Flutter models locally in your browser.

Use an object or an array of objects for model inference.

Dart / Flutter options

Generated code

Generated code will appear here.

Convert JSON to Dart / Flutter

Generate Dart model classes from representative JSON for use in Flutter applications or other Dart projects. Inferred fields use Dart types, and nested objects become separate models that the root class can reference.

The available controls cover common hand-written Flutter model patterns: null-safe fields, final or mutable values, named parameters, required non-null parameters, and optional fromJson and toJson methods.

Dart model and Flutter serialization options

With null safety enabled, fields observed as nullable receive a question mark. Required constructor parameters are added only to fields that are neither missing nor nullable in the supplied samples.

The fromJson factory reads original JSON keys and constructs nested models. The toJson method converts nested models back to maps, so the generated class can support common Flutter data flows without a code-generation package.

Dart / Flutter conversion example

Example JSON input:

[
  {
    "product_id": 12,
    "details": { "display_name": "Notebook" },
    "tags": ["paper", "office"]
  },
  {
    "product_id": 13,
    "details": null,
    "tags": []
  }
]

Generated Dart / Flutter output:

class RootModel {
  final int productId;
  final RootModelDetails? details;
  final List<String> tags;

  RootModel({
    required this.productId,
    this.details,
    required this.tags,
  });

  factory RootModel.fromJson(Map<String, dynamic> json) {
    return RootModel(
      productId: json["product_id"],
      details: json["details"] == null ? null : RootModelDetails.fromJson(json["details"] as Map<String, dynamic>),
      tags: json["tags"],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      "product_id": productId,
      "details": details?.toJson(),
      "tags": tags,
    };
  }
}

class RootModelDetails {
  final String displayName;

  RootModelDetails({
    required this.displayName,
  });

  factory RootModelDetails.fromJson(Map<String, dynamic> json) {
    return RootModelDetails(
      displayName: json["display_name"],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      "display_name": displayName,
    };
  }
}

How to generate Dart / Flutter code

  1. Paste a JSON object or an array of similar objects.
  2. Enter the root Dart model name.
  3. Adjust null safety, field mutability, constructor parameters, required fields, fromJson, and toJson options.
  4. Generate the Dart model, then copy it or download the .dart file.

Frequently asked questions

How does JSON become a Dart model?

The converter infers Dart field types from the sample and creates a class for the root object plus separate classes for nested objects.

Does the generated output work in Flutter?

Yes. The output is ordinary Dart code suitable for Flutter projects. It does not require Freezed, json_serializable, or another package.

How does null safety work?

When nullable fields are enabled, values observed as null receive nullable Dart types. Required parameters are limited to fields that are present and non-null in the sample set.

Can it generate fromJson and toJson?

Yes. Each method can be enabled independently. fromJson reads the original JSON keys, and toJson writes those keys back into a map.

Are nested JSON objects supported?

Yes. Nested objects and arrays of objects become named Dart models, with serialization calls added when fromJson or toJson is enabled.

Private browser-based conversion

Your JSON input, field names, root model name, and generated Dart / Flutter source stay in this browser. They are not sent to a backend, added to the URL, or saved in local storage or cookies.

Related tools

Compare another language-specific converter that uses the same local JSON inference engine.

Back to JSON to Code overview