JSON to Dart model class generator
About JSON to Dart
The JSON to Dart generator turns a sample JSON document into null-safe Dart model classes. Paste an API response and get classes you can use in a Flutter app or a Dart server, with nested objects as their own named classes and arrays as typed lists.
Each class gets a fromJson factory and a toJson method written by hand, so it works without build_runner or code generation packages. Turn the option off if you only want the fields.
Runs in your browser. Nothing is uploaded. The classes are inferred from one sample, so review nullability against your API before you ship them.
How it works
Infer Dart types from JSON values
Whole numbers become int, decimals become double, true and false become bool and text becomes String. Arrays become List<T>. Values that are always null, or that mix types, become dynamic.
Null safety from the sample
A key whose value is null in one array element and set in another gets a nullable type such as String?. A key missing from some elements is nullable too. Nullable fields are optional named parameters, and the rest are required.
fromJson and toJson
fromJson casts each value to its type, reads double fields through num so 12 and 12.5 both work, and calls the nested class's fromJson for objects and lists of objects. toJson writes the original JSON keys back, so snake_case and kebab-case keys survive the round trip.
Names that compile
JSON keys become camelCase field names and nested objects get PascalCase class names in singular form, so an items array yields an Item class. Dart keywords such as class get a Value suffix, and clashing names get a number.
Frequently asked questions
Do I need json_serializable or build_runner?
No. The fromJson and toJson code is written out in full and uses only dart:core types. If your project already uses json_serializable, you can still use the field list as a starting point.
How do I use the generated class?
Decode the response with jsonDecode from dart:convert, then call Root.fromJson(json as Map<String, dynamic>). Call toJson() and jsonEncode to send it back.
Why is a field dynamic?
The sample only had null for that key, an empty array, or values of different types. Add a sample with a real value, or set the type by hand.
Does it work with Flutter?
Yes. The output is plain Dart 3 with sound null safety, so it works in Flutter apps and in Dart command-line or server code.
Is my JSON uploaded?
No. The classes are generated in your browser.
Learn more
Sources & last verified
We checked this tool's behavior and the claims on this page against the specifications below on . The tool runs in your browser, so the output you see is exactly what the engine produced.
- Flutter docs: JSON and serialization
- Dart: Sound null safety
- RFC 8259: The JSON Data Interchange Format
Found a wrong result or an outdated claim? Report an error and we will check it again.