JSON to Dart Class Generator for Flutter Models
Paste the JSON your API returns and get Dart model classes with final fields, a const constructor, a fromJson factory and a toJson method. No json_serializable or build_runner step is needed.
- Types come from every item in a list, so later-only fields are not lost
- Fields that are missing or null in some items become nullable
- Whole numbers become int, numbers with a decimal point become double
- Any JSON key becomes a valid camelCase Dart field name
- Custom root class name, file upload, copy and .dart download
How to Convert JSON to Dart Classes - Step by Step Guide
Input Your JSON Data
Start by adding your JSON data that needs to be converted to Dart classes. The tool will analyze the structure and generate appropriate Flutter-ready Dart code:
Pick a Root Class Name
There is one setting: the Class Name box above the editor. It names the top-level class (Root by default). Everything else is worked out from the JSON itself:
orders become OrderRead the Generated Classes
For this input, id becomes int, price becomes double, and the second order's qty becomes int? because the first order doesn't have it:
{"id":8901240544102066246,"name":"Ana","price":14.50,"tags":["new"],"orders":[{"sku":"A1"},{"sku":"B2","qty":2}]}class Order {
final String sku;
final int? qty;
const Order({
required this.sku,
this.qty,
});
factory Order.fromJson(Map<String, dynamic> json) {
return Order(
sku: json['sku'] as String,
qty: json['qty'] as int?,
);
}
// ...toJson()
}Copy the code or download it as a .dart file, then read your data with Root.fromJson(jsonDecode(text) as Map<String, dynamic>).
Frequently Asked Questions
Do I need json_serializable or build_runner?
No. The classes are plain Dart with hand-written fromJson and toJson methods, so there is no code generation step and no package to add. You only need dart:convert, which ships with Dart, to call jsonDecode.
How does it decide between int, double and String?
It looks at how each number is written in your JSON. Whole numbers like 42 or 8901240544102066246 become int, numbers with a decimal point or exponent like 14.50 or 1.0 become double, and a list that mixes 1 and 2.5 becomes List<double>. Quoted values such as "00501" stay String, so leading zeros are never lost. Doubles are read with (x as num).toDouble(), so a whole number in a double field still works.
What happens when list items have different fields?
Every item in a list is looked at, not just the first one. Fields that only some items have, or that are null in some of them, become nullable (for example int? or String?) and are left out of the required constructor parameters. If the same field holds a number in one item and text in another, it becomes dynamic.
What does it do with keys that are not valid Dart names?
Keys are turned into camelCase field names, while fromJson and toJson keep using your original key. Dashes and spaces are dropped (first-name becomes firstName), names starting with a digit get a field prefix, Dart keywords such as class or default get a Value suffix, and keys that end up with the same name are numbered. Nested classes that would clash with Dart types like List or Map are renamed, for example ListModel.
Will long IDs lose digits?
Not in the generated code or on the Dart VM. A value like 8901240544102066246 becomes an int field, and Dart ints are 64-bit on mobile, desktop and server. Flutter web is the exception: it runs on JavaScript numbers, so the output adds a note when your JSON has ints larger than 2^53.
Is my JSON uploaded anywhere?
No. The classes are generated in your browser and the JSON never leaves your device.