JSON to Dart Converter
Convert JSON to Dart classes instantly. Generate Dart model classes from JSON data for Flutter development.
Upload a JSON or TXT file (max 5MB)
Conversion Options
How to Use:
- Paste your JSON content in the left textarea or upload a JSON file
- Customize conversion options (class name, null safety, methods to generate)
- Click "Convert to Dart" to generate your Dart model classes
- Copy the Dart code or download it as a .dart file
- Use the generated classes in your Flutter/Dart project
Generated Features:
- Properly typed Dart class properties
- fromJson factory constructor for JSON deserialization
- toJson method for JSON serialization
- copyWith method for immutable updates (optional)
- toString method for debugging (optional)
- Equatable support for value equality (optional)
- Null safety support for Dart 2.12+
- Nested class generation for complex objects
Three Real Quirks to Check Before Trusting the Output
This converter infers Dart types entirely from the sample JSON you paste โ it has no schema to fall back on, so the quality of the generated model is only as good as how representative your sample is. Three specific behaviors are worth understanding before you paste generated code straight into a Flutter project:
1. Nested Class Names Come Only From the Field Name โ Duplicates Will Collide
When the converter hits a nested object, it names the generated class after the PascalCase version of that field's key โ not the full path to it. That means if your JSON has both "billingAddress": {...} and "shippingAddress": {...}, you get two distinctly-named classes (BillingAddress, ShippingAddress) โ fine. But if two different objects in your JSON both happen to use the same field name at different nesting levels โ say "user": {"address": {...}} and, separately, "warehouse": {"address": {...}} โ both generate a class literally named Address, and the second declaration will collide with the first in the same output file. Also worth knowing: array-of-object fields get the class named after the plural field itself, with no singularization โ a "items": [{...}] field produces class Items {} and List<Items> items, not the more idiomatic Item. Rename colliding or awkwardly-pluralized generated classes by hand after conversion.
2. A Null Sample Value Can Generate Invalid dynamic?? Syntax
If a field's value in your sample JSON is literally null and Null Safety is checked, the type inference returns dynamic? for that field already โ but the class-field and copyWith generators then append another ? on top of it, producing invalid Dart like final dynamic?? someField;, which won't compile. This only triggers on fields whose sample value is exactly null โ if you can, edit your sample JSON to include a real, non-null example value for every field before converting (e.g. an empty string instead of null, or a representative number) to avoid hitting this, or manually fix the double question mark in the rare fields where a null placeholder is unavoidable.
3. Number and Array Types Are Guessed From a Single Sample Value
-
โข
int vs double depends on how JSON.parse sees the number, not how you wrote it: a price field written as
"price": 19.0in your sample JSON gets parsed to the JavaScript number19(JavaScript doesn't distinguish 19 from 19.0), andNumber.isInteger(19)is true โ so it's typedint, notdouble. If a real API response could later send a fractional value for that field, change the sample to something like19.99before converting so the generator correctly infersdouble. -
โข
Array element type comes from element zero only: for a list field, the converter looks at
value[0]to decide the whole list's Dart type. A mixed-type array, or one whose first element isn't representative of the rest, will produce aList<T>that's wrong for some elements. An empty array in your sample always becomesList<dynamic>regardless of what the field will actually hold in production.
A Note on the copyWith and Equatable Options
The copyWith method's parameters are always generated as nullable (Type? name) so callers can omit fields they don't want to change โ this happens regardless of whether the "Null Safety" checkbox is on, so if you disable Null Safety but enable copyWith, the output will still contain null-safety-only ? syntax that requires a null-safe Dart environment to compile. And checking "Use Equatable" adds an import 'package:equatable/equatable.dart'; line at the top of the output โ remember that package has to actually be added to your project's pubspec.yaml dependencies before the generated code will build.
Frequently Asked Questions
My generated code has "dynamic??" and won't compile โ how do I fix it?
That happens when a field's sample value was null with Null Safety enabled. Either manually delete the extra ? in the affected field/parameter, or re-run the conversion with a non-null placeholder value for that field in your sample JSON.
Two of my generated classes have the same name โ why?
Nested class names are derived only from the field name, not its position in the JSON tree. If two different parent objects each have a nested field with the same name (like two separate "address" objects), both generate a class with that same name and will collide. Rename one manually after conversion.
Why is a price/amount field typed int instead of double?
JavaScript's JSON parser treats 19.0 and 19 identically, so a whole-number sample value always infers int even if the field could hold decimals in production. Use a fractional example value (like 19.99) in your sample JSON if the field should be double.
Does it singularize array field names for the generated class, like "items" โ "Item"?
No โ an array-of-objects field named "items" generates a class literally called Items, matching the field name exactly with no singular/plural transformation. Rename it by hand if you want conventional singular class naming.
Should I trust the generated code as production-ready without review?
Treat it as a strong first draft. Because type inference works from one JSON sample rather than a schema, always sanity-check nested class names for collisions, verify int/double choices against real API behavior, and confirm nullable fields make sense before shipping the generated models.
