Developer

JSON to Dart Model

Generate Dart model classes from a JSON sample with null safe types, nested classes, typed lists and working fromJson and toJson methods for Flutter projects.

Last reviewed by the Radiatus Cloud team

Generated Dart appears here.

Need this built for your product?

We design, build & host secure software & APIs.

Talk to an engineer

Flutter without a code generator

Dart has no runtime reflection in release builds, so a Flutter app cannot deserialise JSON generically the way a Java or Python client can. Every model needs an explicit fromJson constructor. Teams either adopt build_runner with json_serializable, which adds a build step and a generated part file to every model, or they write the constructors by hand. Hand written constructors are perfectly idiomatic Dart and are what most small projects actually ship, but they are repetitive and easy to get subtly wrong.

Null safety in the constructor, not the field

Since Dart 2.12 a field is non nullable unless declared otherwise, and a non nullable field must be initialised. The failure mode is not a compile error but a runtime type cast: reading json['count'] as int when the key is absent throws, and the stack trace points at the model rather than the response. This generator marks a field nullable whenever the sample showed a null or a missing key, and reads it defensively so an unexpected absence produces null rather than an exception.

Lists and nested models

Nested objects become their own classes, and lists of objects are mapped element by element through the nested fromJson so you get a typed List rather than a List of dynamic. Lists of scalars are cast through a typed map for the same reason. The toJson methods mirror the structure, which matters because a model that can only be read is half a model when you need to PUT it back.

Related tools

  • JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
  • JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
  • Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
  • HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.

Frequently Asked Questions

Should I use this or json_serializable?

json_serializable is the better choice for a large app because it stays in sync with the class through a build step. Hand written models are fine for a handful of endpoints and avoid build_runner entirely. The output here is ordinary Dart either way.

Why are the fromJson reads written defensively?

Because a cast such as json["x"] as int throws when the key is missing, and the exception surfaces far from the cause. Reading into a nullable local first turns a crash into a null you can handle.

How are DateTime fields handled?

Strings that match ISO 8601 are typed DateTime and parsed with DateTime.parse in fromJson, then written back with toIso8601String. Anything ambiguous stays a String, since guessing a date format is worse than not guessing.

Are the generated classes immutable?

Fields are declared final and the constructor takes named required parameters, which is the common Flutter convention. Add copyWith yourself if you need it; generating it would double the output for a method not every model needs.

What about a list of mixed types?

It becomes List<dynamic> and the tool flags it. A heterogeneous list normally means the payload has a discriminator field, which is better modelled as a sealed class hierarchy than inferred.

Privacy & Security

Everything runs in your browser; nothing is uploaded.

Data: None
Client-side-Side
Active
v1.0

How to Use

Paste a JSON response, name the root class, and copy the generated null safe Dart models.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.