How to convert JSON to Dart
- Paste a JSON object or array, for example a response from the API you are calling.
- Set the name of the root type.
- Copy the generated Dart code into your project.
What you get
- Classes with
finalfields, a named constructor and null safety. - Hand-written
fromJsonfactories andtoJsonmethods, including nested objects and lists. - No
build_runnerorjson_serializableneeded: the code works as is.
Tips for accurate results
The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.
Frequently asked questions
Is my JSON sent to a server?
No. The code is generated in your browser, so API responses and other private data never leave your device.
How do I use the classes in Flutter?
Decode the response with jsonDecode(response.body) and pass the map to Root.fromJson(...). To send data back, call jsonEncode(value.toJson()).
Why not json_serializable?
json_serializable needs annotations and a build_runner step. The generated classes contain the conversion code directly, so you can paste them and use them right away.
How are numbers handled?
Whole numbers become int. If any sample has decimals the field becomes double, read with (json[key] as num).toDouble() so values like 10 still decode correctly.