JSON to Dart
Generate null-safe Dart (Flutter) model classes from a JSON sample.
JSON to Dart – Null-safe model classes for Flutter
The JSON to Dart converter turns a sample API response into ready-to-paste Dart classes. Every class gets typed fields, a named constructor with required parameters, a fromJson factory and a toJson method, so you can decode a response with jsonDecode and get a fully typed object in one line. The generated code is sound-null-safe and has no dependency on json_serializable or build_runner.
What you get
- Typed fields:
String,int,double,bool, nested classes andList<T>. Values that arenullor missing in some array items become nullable (String?) and lose therequiredkeyword. - Safe number handling: integers are read with
(json['id'] as num).toInt()and decimals with.toDouble(), so a backend that sends10instead of10.0does not crash your app. - Nested objects and lists are mapped recursively with
.map((e) => Item.fromJson(e)).toList(). - Options: immutable
finalfields with aconstconstructor,DateTime.parsefor ISO timestamps, and an optionalcopyWithmethod for state management with Provider, Riverpod or Bloc.
Typical Flutter workflow
Copy a real response from your browser's network tab or from Postman, paste it here, set the root class name, and drop the result into lib/models/. Then call Order.fromJson(jsonDecode(response.body)) after an http or dio request. Because the code is plain Dart, you can review and edit every line — rename a class, add a computed getter, or switch a field to an enum.
Tips
Paste an array with several items when fields are sometimes missing; the tool merges them and marks the absent keys nullable. Keys that are not valid Dart identifiers (first-name, class) are renamed to camelCase or suffixed, while the original key is kept in the json['...'] lookup.
Related tools
Check your input with the JSON Validator, or generate TypeScript and Go models from the same data.
Frequently Asked Questions
Is my JSON uploaded anywhere?
No. Parsing and code generation happen in your browser, so private API responses never leave your device.
Do I need json_serializable or build_runner?
No. The generated fromJson and toJson methods are hand-written style Dart with no code generation step or annotations, so they compile in any Dart 3 or Flutter project as-is.
Why is a field nullable?
A field becomes nullable when its sample value is null or when it is missing from at least one object in an array. Add a non-null example value if the field is actually always present.
How are dates handled?
By default ISO timestamps stay String. Turn on "DateTime for timestamps" to get DateTime fields parsed with DateTime.parse and serialized with toIso8601String().