JSON to Dart Converter Online — Generate Class

Generate Dart classes from any JSON payload — null-safe types, fromJson factory, toJson method, and nested classes for Flutter and Dart projects. 100% in your browser.

What is a JSON to Dart converter?

A JSON to Dart converter reads a JSON sample and emits typed Dart classes that mirror the JSON shape — final fields, named constructors, fromJson factory constructors, and toJson methods. The output drops straight into a Flutter, Dart server, or AngularDart project and deserializes with jsonDecode from dart:convert without any code generation step.

Writing model classes by hand from a 200-field Flutter API payload wastes hours and is bug-prone — a single typo in a key name silently nulls out a value at runtime. OpenFormatter's converter walks the JSON tree once, generates idiomatic Dart, and runs entirely in your browser so internal API responses never leave your machine.

How to generate Dart classes from JSON — 4 steps

  1. Paste a real JSON response. Use a representative sample — type inference quality depends on it. Booleans must be true/false (not 0/1), numbers must be unquoted.
  2. Click Convert. The tool emits a Root class plus one separate class per nested object, each with fromJson and toJson methods.
  3. Copy and paste into your IDE. Each class is independent — split them into separate .dart files in your lib/models/ folder.
  4. Decode the JSON. final root = Root.fromJson(jsonDecode(response.body)); — that is all Dart needs once the class has a fromJson factory.

JSON to Dart type mapping

Sample JSON

{
  "id": 42,
  "name": "Ada Lovelace",
  "active": true,
  "score": 98.5,
  "address": { "city": "London" },
  "tags": ["admin", "engineer"]
}

Generated Dart class

class Root {
  final int id;
  final String name;
  final bool active;
  final double score;
  final Address address;
  final List<String> tags;

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

  factory Root.fromJson(Map<String, dynamic> json) => Root(
    id: json['id'],
    name: json['name'],
    active: json['active'],
    score: (json['score'] as num).toDouble(),
    address: Address.fromJson(json['address']),
    tags: List<String>.from(json['tags']),
  );

  Map<String, dynamic> toJson() => {
    'id': id,
    'name': name,
    'active': active,
    'score': score,
    'address': address.toJson(),
    'tags': tags,
  };
}

class Address {
  final String city;
  Address({required this.city});
  factory Address.fromJson(Map<String, dynamic> json) =>
      Address(city: json['city']);
  Map<String, dynamic> toJson() => {'city': city};
}

fromJson and toJson

Every class ships with a factory fromJson constructor and a toJson method — no build_runner step, no extra packages. Pair with dart:convert and you are done.

Sound null safety

Generated for Dart 2.12+ — non-null fields are non-nullable, JSON null fields fall back to dynamic so you can refine to Type? as needed.

Client-Side Only

JSON is parsed in JavaScript inside the browser. Internal Flutter API responses, tokens, or PII never reach a server.

Common use cases

  • check_circleGenerating Flutter REST API model classes from a real JSON response
  • check_circleBuilding Firestore document models for cloud_firestore reads
  • check_circleModelling Firebase Realtime Database snapshots into typed classes
  • check_circleProducing GraphQL response shapes for a Flutter app
  • check_circleCreating BLoC, Riverpod, or Provider state classes from JSON
  • check_circleModelling Dio HTTP client response bodies
  • check_circleBuilding shared_preferences or hive serialization classes
  • check_circleModelling Stripe, Twilio, or any third-party SaaS webhook payload

Why client-side generation matters

The JSON you paste often contains real customer data, OAuth tokens, signed URLs, or internal field names you do not want indexed by a third-party converter. OpenFormatter generates the Dart entirely in JavaScript on your device — open the Network tab in DevTools and you will see zero requests when you click Convert. Safe for enterprise use, safe behind a corporate proxy, safe when the API contract is itself confidential.

Need other Dart and Flutter tooling?

Format JSON, validate JSON, or generate types for other mobile languages — all browser-side.

Frequently Asked Questions

Are fromJson/toJson methods generated?

Yes. Every generated class includes a factory ClassName.fromJson(Map<String, dynamic> json) constructor and a Map<String, dynamic> toJson() method. You can call them directly with the Map you get from jsonDecode(httpResponse.body) — no build_runner, no code generation step required.

Does it support null safety?

Yes. Dart 2.12+ sound null safety is the target. Fields whose JSON sample value is null are typed as dynamic; fields with concrete non-null values become non-nullable types like String, int, bool, and double. To express an optional field, change the type to String? after copying — fromJson will still pick up the missing key as null without throwing.

Will the output work with json_serializable?

The generator emits hand-written serialization to keep the output dependency-free. If you prefer json_serializable, add @JsonSerializable() above each class, replace the body with part 'model.g.dart'; factory ClassName.fromJson(Map<String, dynamic> json) => _$ClassNameFromJson(json); Map<String, dynamic> toJson() => _$ClassNameToJson(this); — then run dart run build_runner build to generate the .g.dart file.

Can I use this for Flutter?

Yes. The generated Dart classes work in any Flutter project. Drop them into lib/models/ and call YourModel.fromJson(jsonDecode(response.body)) inside a FutureBuilder or Riverpod / BLoC provider. The output uses only the dart:core types so no extra packages are required.

How are nested JSON objects modelled?

Each nested object becomes its own top-level Dart class so you can split them across files. The parent class holds a typed reference (e.g. final Address address;) and the parent fromJson factory delegates to Address.fromJson(json['address']) to instantiate the nested class.

How are JSON arrays of objects mapped?

Arrays of objects become List<ClassName> in Dart and the generated fromJson uses List<dynamic>.from(json['items']).map(ClassName.fromJson) for typed parsing. Arrays of primitives become List<String>, List<int>, List<double>, or List<bool>.

How are Dart reserved words handled?

A JSON key like "class" or "default" collides with a Dart keyword. The generator preserves the JSON key as-is; manually rename the field (e.g. classField) and adjust the fromJson lookup to json['class'] to keep the wire format intact.

Is the JSON uploaded to your servers?

No. Conversion runs entirely in your browser via JavaScript. Open DevTools → Network and click Convert — no requests are made. JSON containing API keys, internal field names, or PII never leaves your machine.

JSON to Dart Converter Online — Generate Class