JSON to Dart Class
Paste JSON and generate clean, null-safe Dart classes with nested models and serialization — ready for Flutter or any Dart project.
Input JSON
Generated Dart
Your generated Dart classes will appear here.About JSON to Dart Class
This free tool converts any JSON object or array into idiomatic, null-safe Dart classes in one click. It inspects your JSON, infers the most specific type for every field, and generates strongly-typed models you can paste straight into a Flutter app or a Dart backend.
It picks the right Dart type for each value — int for whole numbers, double for decimals, bool, String, and DateTime for ISO-8601 timestamps — and builds nested classes for inner objects and List<T> types for arrays. Fields that are null or only present in some array items become nullable (Type?) so your models match real-world API responses. JSON keys in snake_case are converted to camelCase property names.
Output works the way Dart and Flutter developers actually serialize JSON: hand-written fromJson / toJson with no dependencies, json_serializable (@JsonSerializable with part files), or freezed immutable classes — or a plain class with just a constructor. Everything runs entirely in your browser, so your JSON never leaves your device.
How to Use JSON to Dart Class
- Paste a JSON object or array into the input box, or click Load Sample to try it.
- Set the root class name for the generated model.
- Choose how you serialize: manual
fromJson/toJson, json_serializable, freezed, or a plain class. - Pick a date type and toggle
finalfields to match your style. - Copy the generated Dart and paste it into your project.
dynamic when a safe, more specific Dart type cannot be inferred. For json_serializable and freezed, remember to run dart run build_runner build to generate the matching .g.dart / .freezed.dart files.What it handles
- ✅ Nested classes
- ✅ Root arrays via
typedef - ✅ Null safety with
Type? - ✅
intvsdoubledetection - ✅
DateTimeparsing - ✅ Manual, json_serializable & freezed
- ✅
snake_case→camelCase
FAQ
Does this tool send my JSON to a server?
No. All parsing and code generation happens in your browser, so your JSON stays on your device.
Which serialization approaches are supported?
Hand-written fromJson/toJson (no dependencies), json_serializable, and freezed. You can also choose None for a plain class with just a constructor.
Do I need build_runner?
Only for json_serializable and freezed. Those emit part directives and reference generated code, so run dart run build_runner build afterwards. The manual option needs no code generation at all.
How are JSON keys like created_at handled?
They become camelCase properties (createdAt). With manual serialization the original key is read directly; with json_serializable and freezed a @JsonKey(name: 'created_at') annotation is added.
Does it support root-level JSON arrays?
Yes. A root array generates a typedef Root = List<Item>; plus a class for the element shape.
When does a field become nullable?
When its value is null, or when it is missing from some objects in an array. Nullable fields get a ? type and an optional (non-required) constructor parameter.
How does it choose between int and double?
Whole numbers become int and decimals become double. Because JSON has a single number type, the fromJson code reads doubles via (value as num).toDouble() so integer-looking JSON still parses correctly.