Skip to content
100% local

JSON to Dart class

Turn a JSON sample into a Dart class with fromJson, toJson and nested models.

Input
Output

JSON to Dart class

Paste a JSON sample and this tool infers the shape of the data and generates a matching Dart class — the kind you would otherwise hand-write for a Flutter model. Nested objects become their own classes, arrays become typed `List<...>` fields, and every class ships with a named constructor, a `fromJson` factory and a `toJson` method, so the result drops straight into a Flutter or Dart project.

The options control the style of the generated code. "Class name" sets the root class; nested classes are named after the JSON key that introduced them. "Null safety with required fields" marks fields that are present in every sample as `required` with a non-nullable type, and fields that are sometimes missing or null as nullable and optional; turn it off to make every field nullable instead. "json_serializable annotations" swaps the hand-written `fromJson`/`toJson` bodies for `@JsonSerializable()` and `@JsonKey`, which delegate to a generated `.g.dart` part file. "Final fields" makes the class immutable; "Generate copyWith" adds a method for creating a modified copy without mutating the original, and "Generate == and hashCode" adds value equality so two instances with the same field values compare equal. "Indent" switches between 2- and 4-space indentation.

When the same object shape repeats — an array of items that all have the same fields, for example — the tool reuses one class instead of generating a duplicate for each occurrence, and a field only missing from some entries in an array is correctly inferred as optional rather than required. JSON keys that aren't valid Dart identifiers, use different casing, or collide with a keyword or a generated method name (like `copyWith` or `hashCode`) are automatically renamed on the Dart side while the original key is preserved for encoding and decoding.

Everything runs locally in your browser: no JSON sample is ever uploaded, which matters if it holds real user data or an internal API's response shape. Copy the class, download it as a .txt file, or send the output back into the input to convert one nested piece further.

FAQ

How are nested objects and arrays handled?
Each nested object becomes its own Dart class named after the field that introduced it, and an array of objects becomes a typed List<YourClass>. If the same shape appears more than once, the tool reuses a single class instead of duplicating it.
What does "Null safety with required fields" actually change?
When it is on, a field the tool sees in every sample gets a non-nullable type and a `required` constructor parameter; a field that is sometimes missing or null gets a nullable type with no `required` keyword. Turning it off makes every field nullable and optional, which is more tolerant of APIs whose responses vary.
Do I need the json_serializable package?
Only if you turn on the "json_serializable annotations" option, which emits @JsonSerializable()/@JsonKey and a part directive expecting a generated .g.dart file from build_runner. Leave it off and the tool writes plain, dependency-free fromJson/toJson methods instead.
Can it infer the type of a numeric field correctly?
Yes. A field that is always a whole number becomes int; if any sample value has a decimal point, the whole field is widened to double so no value would be truncated.
Is my JSON uploaded anywhere?
No. The class is generated entirely in your browser — your JSON sample never leaves your device.