JSON1

JSON1 / JSON to Dart

JSON to Dart

Generate Dart classes with fromJson and toJson from a JSON sample. Every nested object gets its own class, so decoding a payload never leaves you holding a raw map.

Processed locally
InputJSON
Ready
OutputDart

Converted output appears here as you type.

Good to know

  • Every record in an array is inspected, not just the first, so a field that appears in only some of them is typed as optional rather than required.
  • Identical nested shapes are emitted once and reused, and reserved words are renamed to something legal in this language.

About this tool

Dart has no built-in JSON reflection, so every model class needs fromJson and toJson written by hand. That is a lot of repetitive code for a Flutter app talking to a real API, and this generates all of it.

Every nested object gets its own class with its own pair of methods, so decoding a payload leaves you holding typed models rather than a raw Map<String, dynamic> you have to keep casting.

Are the fields immutable?
Yes. Fields are final with a const constructor and named required parameters, which is the conventional shape for a Flutter model and lets the widget tree treat instances as values.
Why hand-written fromJson instead of json_serializable?
Generated code needs build_runner in the project and a part file next to the class, neither of which exists when you are pasting a model into a scratch file. The methods here are complete as written — no build step, nothing to generate.
How are optional fields decided?
Every record in an array is inspected, not just the first. A field that appears in some records and not others is typed as optional, and a value that is sometimes null widens accordingly. Generators that read only the first element get this wrong on exactly the payloads where it matters.
What happens to a key that is a reserved word?
It is renamed to something legal in the target language, and where the language supports it, an annotation records the original JSON key so serialisation still round-trips.