DEV3 Technologies home

Developer tool

JSON to Dart Model Class Generator

Convert JSON to Dart classes with fromJson and toJson for Flutter. Handles nested objects, lists, nullable fields and snake_case keys. Runs in your browser.

Free, no sign-up. Runs in your browser; nothing is uploaded.

Options

JSON

Dart

The result appears here.

How to use the json to dart model class generator

From JSON to Flutter models

  1. Paste a JSON response into the input box. Use Sample if you just want to see the output.
  2. Enter a root class name. Nested objects become their own classes, named from their keys.
  3. Switch toJson off if you only read data and never send it back.
  4. Copy the Dart code into a file in your models folder.

What you get

Each class has final fields, a constructor with required named parameters, a factory fromJson(Map<String, dynamic> json) and, optionally, a toJson() method. Numbers are typed as int or double depending on the sample, and a double is read through (value as num).toDouble() so a JSON 1 does not crash a field that is usually 1.5.

Lists of objects are mapped with .map((e) => Item.fromJson(e as Map<String, dynamic>)).toList(). Lists of strings, numbers and booleans keep their element type.

Things to check

  • Null in the sample produces a dynamic field, because the real type is unknown. Replace it once you know the type.
  • Mixed types in one key, such as a string in one record and a number in another, also fall back to dynamic.
  • Reserved words like class or default as keys get a Value suffix, for example classValue.
  • Dates arrive as strings. Convert them with DateTime.parse in your own code if you need a DateTime.
  • If you add json_serializable later, keep the class names and replace the hand-written methods with annotations.

Good habits

Feed the tool a response that contains every optional field, run your app against real data, and watch for cast errors in the console. A wrong type in fromJson fails loudly at runtime, which is how you find fields the sample did not cover.

Frequently asked questions

Does it use json_serializable or freezed?

No. It writes plain Dart classes with a fromJson factory and a toJson method that you can paste straight into a project, with no code generation step and no extra packages.

How are snake_case keys handled?

Keys are converted to camelCase field names, such as user_id to userId. The original key is kept inside fromJson and toJson, so the JSON still maps correctly.

When is a field nullable?

A field is nullable when it holds null in the sample, or when it is missing from some objects in an array. Fields present with a real value in every object are marked required.

What if my JSON root is a list?

If the root is a list of objects, the tool builds the class for the item and tells you to map each entry with fromJson. A list of plain values cannot become a class.

Is my data uploaded?

No. The conversion happens locally in your browser tab.