JSON to Dart

Paste an API response and get Dart classes with constructors, a fromJson factory and a matching toJson map.

JSON
Dart
Runs locally in your browser

About the JSON to Dart

Flutter apps decode responses into typed models, and writing those models by hand is slow and easy to get wrong. This generator reads a sample payload and emits one class per distinct object shape, with a named constructor, a fromJson factory that casts each value, and a toJson map that writes it back. Nested objects become their own classes and lists of objects become List<T> with the mapping already written.

Types come from the values in the sample. Whole numbers become int, decimals become double, and a field seen with both is widened to double with a toDouble() cast so an integer in the response does not crash the parse. Objects with the same field layout share one class rather than producing near duplicates.

Every record in a list is inspected, not just the first. A key missing from some records, or present but null, is marked nullable, so the generated constructor stops requiring a value that the server does not always send. Turning off null safety produces plain types for an older code base instead.

Field names are converted to lower camel case while the original key stays inside the fromJson lookup, so a snake case API maps cleanly onto Dart style. For other platforms, try JSON to Swift or JSON to Kotlin.

How to use

  1. Paste a representative API response, or press Sample to load an invoice.
  2. Set Root class to the name you want for the outermost model.
  3. Leave Null safe types ticked for any modern Flutter project.
  4. Copy the classes, or download models.dart into your project.

Common questions

Does the output need json_serializable or build_runner?
No. The fromJson factory and toJson map are plain Dart, so the file compiles on its own with no code generation step.
How are nullable fields decided?
A field is nullable when it is null in the sample or missing from at least one record of a list. Those fields drop the required keyword in the constructor.
What happens with a list of mixed types?
When items do not share a shape the list falls back to List, which keeps the file compiling so you can tighten the type by hand.
Why is my snake case key now camel case?
Dart style uses lower camel case for fields. The original key is preserved in the fromJson lookup and in the toJson map, so the wire format does not change.