How to convert JSON to a Dart model
Three steps, about a minute.
1
Paste your JSON
Paste an API response, drop a .json file onto the editor, or load the sample. The status bar validates as you type and points at the exact line of any syntax error.
2
Pick a style and tune it
Choose plain Dart, json_serializable, Freezed or Equatable. Set the root class name, then toggle null safety, copyWith, date detection, equality and doc comments.
3
Copy or download
Copy the generated classes to the clipboard or download a .dart file straight into your Flutter lib/models folder. Every conversion is saved to local history.
Which Dart model style should you pick?
All four produce working models. The difference is how much they give you, and what they cost in dependencies and build time.
Rule of thumb: start with plain Dart. Move to json_serializable when hand-written fromJson becomes a chore, and to Freezed when your models are app state rather than just transport objects.
JSON to Dart type mapping
How each JSON value is translated, and what to watch out for.
Getting accurate models
The generated code is only as good as the sample you paste. A few habits make a large difference.
✓
Use a fully populated response
Pick a sample where optional fields are filled in. Nulls and missing keys are what produce dynamic fields you then have to fix by hand.
✓
Include several list items
Paste an array with two or three different items. The converter merges their shapes, so genuinely optional keys are correctly marked nullable.
✓
Prefer num for money
An API that returns 10 today can return 10.5 tomorrow. Setting number handling to num avoids a runtime cast error in production.
Frequently asked questions
Everything people usually ask about generating Dart models from JSON.
Is my JSON uploaded to a server?
No. All parsing and code generation runs in your browser with JavaScript. Your JSON never leaves your device, so production API responses, tokens and customer data stay private. Once the page has loaded you can even go offline and it keeps working.
Which Dart code style should I choose?
Use plain Dart when you want zero dependencies and no build step. Use json_serializable when you want fromJson and toJson generated but the class body hand-written. Use Freezed when you want immutability, copyWith, equality and unions from one package. Use Equatable when all you need is value equality with no code generation.
How does the converter handle nested JSON objects?
Every nested object becomes its own Dart class, named after the key that contains it. Arrays of objects produce a List of that class, and the item shapes are merged, so a key that is missing from some items is generated as a nullable field. With Merge identical nested classes enabled, two nested objects with the same field signature collapse into a single reused class instead of two near-duplicates.
What happens to null values in my JSON?
A key whose only observed value is null carries no type information, so it is generated as dynamic. Keys that are sometimes null and sometimes typed become nullable fields of that type, such as String? or int?. Paste a sample with populated values to get the most accurate types.
Does it convert snake_case keys to camelCase fields?
Yes. snake_case, kebab-case and PascalCase keys become idiomatic Dart lowerCamelCase field names. The original key is preserved in the generated fromJson/toJson code, or as a @JsonKey(name: '...') annotation in the json_serializable and Freezed output, so the wire format is unchanged. Set field naming to Keep original JSON keys to turn this off.
Can it detect dates in JSON?
Yes. With date detection enabled, strings matching ISO 8601 forms such as 2024-05-31 or 2024-05-31T12:04:00Z are typed as DateTime, parsed with DateTime.parse and serialized back with toIso8601String(). Unix timestamps are left as numbers, since an integer cannot be told apart from any other number.
Why is a number typed as double instead of int?
JSON has a single number type, so the converter infers from your sample: a value with a decimal point becomes double, a whole number becomes int. Because a JSON 4.0 may decode as an int at runtime, generated double fields are read as num and converted with toDouble(). For money and measurements, choosing num in the settings is the safest option.
Do I need build_runner for the generated code?
Only for json_serializable and Freezed, which emit part files. Add the packages to pubspec.yaml, then run dart run build_runner build --delete-conflicting-outputs. Plain Dart and Equatable output compiles as-is with no build step.
Can I convert a top-level JSON array?
Yes. Paste an array and the converter merges the item shapes into a single class named after your root class name. In your code, map the decoded list with (jsonDecode(body) as List).map(MyClass.fromJson).toList().
Where is my conversion history stored?
In your browser only, using localStorage. The last 20 conversions are kept on this device, are never sent anywhere, and can be cleared at any time from the history panel.
Is the JSON to Dart Model Converter free?
Yes. Completely free, no sign-up, and no limit on payload size or on how many models you generate.