JSON to Dart Model
Paste JSON and get complete Dart model classes for Flutter or Dart servers, without code generation packages. Each class has final fields, a const constructor with named required parameters, a fromJson factory that converts nested objects, lists and dates, a toJson method, and optionally copyWith. Types are null-safe, with nullable fields where the sample shows missing or null values.
- Runs in your browser
- No sign-up
- Free to use
How to use JSON to Dart Model
- Paste a JSON sample from your API.
- Set the root class name.
- Choose date parsing and copyWith.
- Copy the classes or download models.dart.
JSON to Dart Model features
Complete classes
Fields, constructor, fromJson, toJson and optional copyWith.
Null safety
Type? and optional parameters for missing or null fields.
Nested data
Converts nested objects and lists of objects in both directions.
Number handling
num.toDouble() so 12 and 12.5 both read as double.
Dates
DateTime.parse and toIso8601String for ISO strings.
No build_runner
Plain Dart code; nothing to generate later.
When to use JSON to Dart Model
- Parsing a REST API response in a Flutter app.
- Modelling Firebase or Supabase documents.
- Creating fixtures for widget tests.
- Converting backend DTOs for a Dart Frog or Shelf server.
JSON to Dart Model FAQ
How do I use the generated class?
Decode the response with jsonDecode, then call Model.fromJson(json as Map<String, dynamic>). Use toJson() and jsonEncode to send data back.
Why (json[…] as num).toDouble()?
JSON does not distinguish 12 from 12.0, and Dart decodes 12 as an int. Casting through num avoids a type error when a decimal field happens to hold a whole number.
Do I need json_serializable?
No. The generated code is plain Dart. If your project already uses json_serializable or freezed, you can still use the field types from here.
What does copyWith do?
It returns a copy with some fields changed, which is the usual way to update immutable objects in Flutter state management.
What if a field has mixed types?
It becomes dynamic and is passed through as decoded.
Is my JSON uploaded?
No. The classes are generated in your browser.
Dart models without code generation
Dart’s jsonDecode returns maps and lists of dynamic values, which are awkward to use and give no compile-time safety. Flutter projects therefore wrap JSON in model classes with a fromJson factory and a toJson method. Packages such as json_serializable generate those methods with build_runner, but plenty of projects prefer plain code that needs no extra build step. This generator writes that code directly.
Each JSON object becomes a class with final fields and a const constructor using named parameters. Fields that were present and non-null in every sample object are required; others are nullable and optional. The fromJson factory reads each key with the right conversion: nested objects call their own fromJson, lists are mapped element by element, and dates are parsed with DateTime.parse.
Numbers need special care in Dart. A JSON value of 12 is decoded as int even when the field normally holds decimals, and casting it directly to double throws at run time. The generated code reads decimal fields through num and calls toDouble(), which accepts both forms. Integer fields are cast to int.
The toJson method mirrors fromJson, converting nested objects and dates back into JSON-compatible values with the original keys, so models can be sent to an API or stored locally. The optional copyWith method supports the immutable update pattern common with Provider, Riverpod and Bloc.
Keys that are not valid Dart identifiers, such as "is-active", become camelCase field names while fromJson and toJson keep using the exact key. Review the nullability against the API documentation, since a sample cannot reveal every optional field.