CalcCafe

JSON to Dart

Paste any JSON and instantly generate idiomatic Dart data classes with inferred types and fromJson constructors.

Example

Given this JSON:

{ "id": 1, "name": "Ada", "tags": ["a","b"], "address": { "city": "London" } }

JSON to Dart produces:

class Root {
 final int id;
 final String name;
 final List<String> tags;
 final Address address;

 Root({required this.id, required this.name, required this.tags, required this.address});

 factory Root.fromJson(Map<String, dynamic> json) => Root(
    id: json['id'] as int,
    name: json['name'] as String,
    tags: (json['tags'] as List<dynamic>).cast<String>(),
    address: Address.fromJson(json['address'] as Map<String, dynamic>),
   );
}

How it works

Parses your JSON, infers Dart types (String, int, double, bool, List, nested classes) and emits a Root class plus a class for every nested object. Conversion runs live as you type.

Good to know

JSON to Dart turns a raw JSON payload into ready-to-use Dart data classes, complete with typed fields and fromJson factory constructors. It is aimed at Flutter and Dart developers who need to model an API response or a config file as strongly typed objects without hand-writing the boilerplate. You paste JSON on the left, and idiomatic Dart appears on the right as you type.

Reach for it whenever you hit a new endpoint and want a quick, accurate scaffold for deserialization. The converter walks the whole structure: scalars become String, int, double, or bool; nested objects each get their own class; and arrays of objects produce a singularized class name (an items array yields an Item class) with a mapped fromJson that calls the child factory on every element. The top-level object is always named Root.

Read the output as a starting point rather than a finished model. Every field is generated as final and marked required in the constructor, so the types reflect exactly what your sample contained. A whole number infers as int and a fractional one as double; if a field is sometimes null or absent in real responses, you will want to make it nullable or relax the type after generating.

Frequently asked questions

How are int and double distinguished?
Whole numbers like 42 become int, while numbers with a fractional part like 9.5 become double. If a value could be either in your real data, change the field type to num or double after generating.
What happens with arrays of objects?
An array of objects generates a dedicated class using a singularized name (for example "items" produces an Item class), and the field becomes Listwith a mapping fromJson that calls Item.fromJson on each element.
Is my data uploaded anywhere?
No — it runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

Does JSON to Dart generate toJson methods?
No. The generated classes include typed fields and a fromJson factory for deserialization, but not a toJson method for serializing back to JSON. You would add that manually or use a code-generation package if you need round-trip serialization.
How are nullable fields handled in the generated Dart code?
Fields are generated as non-nullable and required based on the sample you paste, so a JSON null infers as dynamic rather than a nullable type. To get proper nullability like String?, edit the field type and remove the required keyword after generating.
Does this work with json_serializable or freezed?
It produces plain hand-written Dart classes with a manual fromJson, independent of any package. If you prefer json_serializable or freezed, you can use the output as a structural reference and add the relevant annotations and part directives yourself.
What happens if my JSON has duplicate or conflicting nested object shapes?
Each nested object generates its own class, and the tool de-duplicates class names by appending a number when a name is already taken. For arrays of objects it merges the keys it sees across elements to build a single child class.
Can it convert a top-level JSON array or a single scalar value?
Yes. A top-level array produces a typedef Root for the list type plus any element classes, and a top-level scalar produces a typedef Root for that primitive type. Object roots produce a full Root class.
How do I rename the generated Root class?
The root class is always emitted with the name Root. To use a different name, do a find-and-replace on Root in the generated output, or rename it in your IDE after pasting the code into your project.
Why did a numeric field become int when my real data can be a decimal?
Type inference looks only at the sample value, so a whole number like 42 is treated as int even if the same field elsewhere holds 9.5. Change such fields to double or num so they accept both whole and fractional values.

Related tools