JSON to Dart
This JSON to Dart tool generates model classes for Flutter and Dart projects. Fields, a constructor and fromJson / toJson methods are all produced together, nullable types are inferred accurately, and json_serializable and Freezed annotation styles are supported. Generation runs locally in your browser.
How to use it
- 1
Paste your JSON
Paste API JSON; nested objects become related classes and lists become List<T>.
- 2
Set the root class name
The default is User; change it for your domain. Nullable fields get nullable type annotations.
- 3
Copy the Dart code
Generate a complete class with hand-written fromJson / toJson, or use the json_serializable / Freezed annotation style.
- 4
Use it in your app
Call User.fromJson(jsonDecode(response.body)) to parse and jsonEncode(user.toJson()) to send.
Key features
Complete fromJson / toJson
A named constructor and serialisation methods are generated so http or dio response data maps straight to User.fromJson.
Null-safety support
Null fields are marked as nullable types (String?), compatible with Dart 2.12+ null safety.
Multiple code styles
Plain hand-written classes, json_serializable annotations or Freezed-compatible definitions, matching your team default.
Full nesting and collections
Nested objects cascade into their own fromJson, and List<Map> is inferred as a strongly typed List<Address>.
Strong typing over dynamic
Fields that can be determined get concrete types; only conflicting or unknown fields fall back to dynamic.
Local and private
Generation runs in your browser and the data is not uploaded.
Common errors & troubleshooting
- ! When using json_serializable, configure build_runner in pubspec and run dart run build_runner build.
- ! Flutter projects widely adopt null safety, so keep the ? markers on fields the API may omit to avoid parsing exceptions.
- ! Naming follows Dart lowerCamelCase, with the original JSON key mapped through the key string so send and receive stay unaffected.
- ! Keep the part directive filename consistent with the class file when using generated styles.
Frequently asked questions
How do I use the generated class?
final user = User.fromJson(jsonDecode(response.body)); and jsonEncode(user.toJson()) when sending a request. The fromJson / toJson of nested objects are cascaded automatically.
Should I choose Freezed or json_serializable?
json_serializable is the official, most lightweight option; Freezed adds immutability, copyWith and union types. If your team already uses Freezed, pick that annotation style and keep the part directive filename consistent.
How are dynamic and concrete types distinguished?
Fields that can be determined from the samples get concrete types; only conflicts or unknowns (such as an arbitrary object) fall back to dynamic, and those fields should be narrowed by hand after checking the API docs.
Is my data uploaded?
No. Generation runs locally in your browser.
Related tools
JSON to Kotlin
Generate Kotlin data classes from JSON. Supports Jackson, kotlinx.serialization and Klaxon, with a custom package name and accurate nullable (?) type annotations. Runs locally.
JSON to Swift
Generate Swift models from JSON that conform to Codable. CodingKeys handle snake_case mapping, and optional properties are inferred. Choose struct or class. Runs locally in your browser.
JSON to TypeScript
Generate TypeScript interface or type definitions from a sample JSON payload.
JSON Formatter
Format, beautify and validate JSON in your browser. Errors point to the exact line and column, and you can indent with 2 spaces, 4 spaces or a tab.