{ } JSON Workbench100% Private • Zero Server Uploads

"JSON to Dart":{ }

Paste a JSON sample and get clean Dart classes. Nested objects become named types, arrays become typed collections, and nullable fields are handled. Powered by quicktype's inference engine running 100% in your browser: nothing is uploaded, so real API payloads stay on your machine.

What is a JSON to Dart converter?

Hand-writing classes for an API response is slow and error-prone. This tool infers Dart classes from a JSON sample: nested objects become named types, arrays become typed collections, and null/missing values become optional fields. It runs quicktype's inference engine entirely in your browser, so real API payloads (often containing user data or credentials) never leave your machine.

Other languages from the same JSON

The same generator also writes TypeScript, Python, Go, Java, C#, Rust, Kotlin, Swift, Ruby, PHP, Pydantic, Zod from the same sample, and a JSON Schema if you need a language-neutral contract.

Dart mapping notes

  • Flutter-ready model classes: final fields, a named constructor, and fromJson / toJson inside each class. No packages or build_runner needed, only dart:convert.
  • Null-safe: always-present fields are required and non-nullable; fields missing from part of your sample become optional nullable types (String?).
  • Integers map to int, decimals to double (read with ?.toDouble() so whole numbers don't crash), and ISO 8601 strings to DateTime via DateTime.parse.

Use the model in Flutter

Fetch and parse a single object with the http package:

import 'package:http/http.dart' as http;

Future<Root> fetchRepo() async {
  final res = await http.get(Uri.parse('https://api.example.com/repos/42'));
  if (res.statusCode != 200) throw Exception('HTTP ${res.statusCode}');
  return Root.fromRawJson(res.body);
}

Parse a JSON list into a List of models:

import 'dart:convert';

final List<Root> repos = (jsonDecode(res.body) as List)
    .map((e) => Root.fromJson(e as Map<String, dynamic>))
    .toList();

fromRawJson takes the raw response string; fromJson takes an already-decoded Map. toJson() returns a Map ready for jsonEncode.

Plain classes, json_serializable or freezed?

  • These generated classes: zero dependencies and no code generation step. Best for small apps, prototypes, and teams that don't want build_runner.
  • json_serializable: annotate classes with @JsonSerializable() and run dart run build_runner build. Worth it when you have dozens of models and want the mapping regenerated as they change.
  • freezed: adds immutability, copyWith, value equality and union types on top of json_serializable. Good for state management, heavier setup.

You can start with the generated classes and migrate later: the field names and types carry over unchanged.

Common Dart JSON pitfalls

  • "type 'double' is not a subtype of type 'int'": the sample had 1 but the API sent 1.5. Put a decimal in your sample (the field becomes double) or type it num.
  • "Null is not a subtype of type 'String'": the API omitted a key your sample always had. Paste several objects (an array) so sometimes-missing keys become nullable.
  • List<dynamic> errors: cast decoded lists with as List and each item with as Map<String, dynamic>, as in the example above.

How to use

  1. Paste a JSON sample (an API response works well) into the Input pane.
  2. Generated Dart classes appear instantly. Nested objects become their own named types.
  3. Non-standard JSON (single quotes, trailing commas, comments) is auto-repaired first.
  4. Copy the code into your project.

Examples

JSON → Dart classes

Input
{
  "id": 42,
  "name": "workbench",
  "owner": { "email": "[email protected]", "active": true }
}
Output
import 'dart:convert';

class Root {
    final int id;
    final String name;
    final Owner owner;

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

    factory Root.fromRawJson(String str) => Root.fromJson(json.decode(str));

    String toRawJson() => json.encode(toJson());

    factory Root.fromJson(Map<String, dynamic> json) => Root(
        id: json["id"],
        name: json["name"],
        owner: Owner.fromJson(json["owner"]),
    );

    Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
        "owner": owner.toJson(),
    };
}

// class Owner { ... } is generated the same way

FAQ

How do I convert JSON to Dart types?

Paste any JSON sample. The classes are inferred from the values and nesting, entirely in your browser. Nothing is uploaded.

How are nested objects handled?

Each distinct nested object becomes its own named type, referenced from the parent, arrays of objects included.

What about optional or null fields?

Fields that are null or missing in parts of the sample are typed as optional/nullable in the generated code.

Can I paste multiple samples?

Paste an array of objects: the type is inferred from the union of all items, which catches optional fields a single sample would miss.

Is the output null-safe?

Yes. It targets Dart 2.12+ and Dart 3 sound null safety: only keys missing from some of your sample objects become nullable, so the compiler catches real nulls instead of you sprinkling !.

How do I convert a JSON list to a List of Dart objects?

Decode the body, cast it to List, and map each item through fromJson: (jsonDecode(body) as List).map((e) => Root.fromJson(e)).toList().

Does it work with Flutter?

Yes. The output is plain Dart that only imports dart:convert, so it works in Flutter (mobile, web, desktop) and in server-side Dart.

What's the difference between fromJson and fromRawJson?

fromJson takes a decoded Map<String, dynamic>; fromRawJson takes the raw JSON string and decodes it for you. toJson and toRawJson mirror them.

Is my JSON uploaded?

No. Generation runs 100% in your browser via quicktype's engine. Nothing is uploaded.

Related tools