JSON to Dart Class Generator
Paste JSON and instantly generate Dart classes with fromJson/toJson methods, null safety, and nested object support
Paste any JSON response and get typed Dart classes back — with fromJson, toJson, null safety, and nested object support already wired up. No more hand-writing model boilerplate or guessing field types from a 200-line API payload.
Pick your root class name, toggle the options you need, and hit Generate. Arrays, nested objects, nullable fields — it handles all of it. And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool parses your JSON, walks every key-value pair, and maps each value to the right Dart type — String, int, double, bool, List, or a nested class. When it hits an object inside your JSON, it creates a separate Dart class for that object automatically. The output includes factory constructors for deserialization and toJson methods for serialization, so you can drop the code straight into your project.
Examples
Simple User Profile
A flat JSON object from a user API endpoint — no nesting, just basic fields.
{
"name": "Alice",
"age": 28,
"email": "[email protected]",
"active": true
}
class User {
String name;
int age;
String email;
bool active;
User.fromJson(Map<String, dynamic> json)
: name = json['name'],
age = json['age'],
email = json['email'],
active = json['active'];
}
Nested Order with Items Array
An e-commerce order response. The converter creates separate classes for the order and each item inside the array.
{
"orderId": 4521,
"total": 89.97,
"items": [
{
"sku": "SHIRT-M",
"price": 29.99,
"qty": 3
}
]
}
class Order {
int orderId;
double total;
List<Items> items;
Order.fromJson(Map<String, dynamic> json)
: orderId = json['orderId'],
total = json['total'],
items = (json['items'] as List)
.map((e) => Items.fromJson(e))
.toList();
}
class Items {
String sku;
double price;
int qty;
...
}
Deeply Nested Config with Null Safety
App config JSON where some fields might be null. With null safety toggled on, the generated Dart code marks nullable fields with ? and adds null checks.
{
"appName": "MyApp",
"version": "2.1.0",
"settings": {
"darkMode": true,
"locale": null,
"notifications": {
"push": true,
"email": false
}
}
}
class Config {
String appName;
String version;
Settings settings;
...
}
class Settings {
bool darkMode;
String? locale;
Notifications notifications;
...
}
class Notifications {
bool push;
bool email;
...
}
Who Uses This
Turn REST API responses into type-safe model classes without writing boilerplate by hand.
Share an API response JSON with the mobile team and generate matching Dart models in seconds.
Learn how JSON maps to Dart types by comparing the input and output side by side.
Prototype Flutter apps faster by generating all model classes from a sample API response in one go.
Common Mistakes
Trailing commas, single quotes instead of double quotes, or unquoted keys will all fail. Run your JSON through a validator first if you're getting parse errors.
If your JSON starts with [ instead of {, wrap it in an object first: {"items": [...]}. The converter expects a root object to create the top-level class.
The default class name might not match your domain model. Change it before generating, or you will end up with a generic name like Root scattered through your codebase.
A field with value 10 looks like an int, but the API might return 10.5 next time. Check your API docs and adjust the generated type if the field can hold decimals.
Technical Details
- Processing: 100% client-side — your JSON never leaves the browser
- Browser Support: Chrome, Firefox, Safari, Edge
- Null Safety: Optional — toggle on for Dart 2.12+ sound null safety syntax
- Nested Depth: No hard limit; handles deeply nested JSON structures
- Output: Copy to clipboard or download as a .dart file
Frequently Asked Questions
Does this support Dart null safety?
Yes. Toggle the null safety option and the generated classes will use nullable types (String?, int?) for fields that are null in your JSON. Fields with actual values stay non-nullable.
Can I convert nested JSON objects?
Absolutely. Every nested object in your JSON gets its own Dart class. A three-level-deep JSON structure produces three separate classes, each with proper type references to the others.
What happens with JSON arrays?
Arrays become List<Type> in Dart. If the array contains objects, the converter creates a class for that object and types the list accordingly — so "users": [{"name": "Jo"}] becomes List<Users>.
Is my JSON data sent to a server?
No. The conversion happens entirely in your browser with JavaScript. Nothing is uploaded, stored, or logged. You can disconnect from the internet and the tool still works.
How do I use the generated code in Flutter?
Copy the output or download the .dart file, then drop it into your Flutter project's lib/models/ folder. Import it where needed and call YourClass.fromJson(jsonDecode(response.body)) to deserialize API responses.