Done
Free · No sign-up · Instant

JSON to Dart Converter

Paste your JSON and get typed, null-safe Dart model classes for Flutter — with fromJson, toJson, nested class generation, and lists of objects handled automatically.

Last reviewed: August 24, 2026 Built by Khalil Rahman 100% browser-based
Try:
Ready
Ready

Dart 3 Null Safety

Required constructor params, ? on optional fields

Nested Classes

Sub-objects get their own typed model

Lists of Objects

Typed List<T> with proper parsing

json_serializable

Optional code-gen annotations

Your JSON never leaves your browser. All parsing and class generation happens locally in JavaScript. The only network requests are the Bootstrap Icons stylesheet and, if you accept the cookie banner, Google Analytics — which sees page visits, never the JSON you paste.

How JSON to Dart conversion actually works

When your Flutter app talks to a backend, the backend sends data as JSON. JSON is easy for the server to produce but awkward for a strongly typed language like Dart to consume — you cannot write user.name against a raw Map<String, dynamic> without losing the compiler's help. Converting JSON into a Dart class gives you real types, autocomplete, and compile-time checks.

Each class needs two methods: fromJson (takes a Map and produces an instance) and toJson (takes an instance and produces a Map). Writing these by hand for a single model is manageable. For an app with 15 models, most of which have nested objects and lists, it becomes a multi-hour chore where a single missed null check causes a runtime crash in production.

This tool does that conversion for you — with correct null safety, nested class generation, and list handling — in one click.

How this tool helps Flutter beginners

The problem with hand-writing models

You have to write the class, declare each field with the right type, write the constructor, write fromJson for every field (with type casts and null checks), write toJson, and handle nested objects and lists manually. The first time you forget to null-check a field, or you cast as String when the API sometimes returns an int, you get a TypeError at runtime — usually the worst possible time.

What this tool generates for you

Paste the JSON sample, click Convert, and you get a complete Dart file with typed fields, a constructor with required for non-nullable fields, a fromJson factory that handles nulls and type coercion safely, a toJson method that round-trips correctly, and separate classes for every nested object and list item. The generated code compiles under Dart 3 sound null safety.

Nested objects and lists

This is where hand-written code breaks most often. Take this sample:

{
  "id": 1,
  "name": "Alice",
  "profile": {
    "age": 28,
    "city": "Berlin"
  },
  "orders": [
    { "id": "o_1", "total": 49.99 }
  ]
}

The generated Dart file contains three classes:

Each class has its own fromJson/toJson, and the parent's fromJson correctly calls UserProfile.fromJson on the nested map and UserOrder.fromJson on each element of the list.

Common mistakes when writing models by hand

Using the generated file in your Flutter project

Save the generated code as lib/models/user.dart (or wherever your project keeps models). Then in your repository or service layer, parse the response:

import 'dart:convert';
import 'models/user.dart';

Future<User> fetchUser(String url) async {
  final response = await http.get(Uri.parse(url));
  final json = jsonDecode(response.body) as Map<String, dynamic>;
  return User.fromJson(json);
}

For lists, User.listFromJson(jsonDecode(response.body) as List) would work if you generate a list at the root — this tool includes that pattern when your root is an array.

When to use json_serializable instead

This tool has an option to add json_serializable annotations. That is the right choice when your models have custom types (dates, enums, value objects) that you want to annotate with @JsonKey(fromJson:, toJson:) or custom JsonConverter classes. The generated code becomes much shorter — fromJson and toJson delegate to _$UserFromJson and _$UserToJson, and you run flutter pub run build_runner build to produce the actual logic.

If you do not want to add a build step, leave the checkbox off — you get a fully self-contained file that compiles without any dependency on json_serializable.

Things this tool does not do

Khalil Rahman

Full-stack developer and founder of SkillsInsider. I've written a lot of hand-typed Flutter models and I know exactly which mistakes hurt — usually a missing null-check on a field the API happened to return null for once. If this tool generates something that does not compile under Dart 3, send me a message with the JSON and the error.

Frequently asked questions

Yes. Every generated class uses Dart 3 sound null safety. Non-nullable fields are marked required in the constructor, and fields whose JSON value is null get a nullable type with a ? mark. This is what prevents NullThrownError and TypeError exceptions in production — which are the most common crash causes in Flutter apps that consume APIs.

Each nested object becomes its own Dart class with a unique name, referenced as a typed field on the parent. For {"user": {"id": 1}} with a root name of User, the tool generates a UserUser or similar sub-class (the exact name depends on the field key) and a final UserUser user; field with proper fromJson/toJson round-trip. Deeply nested structures generate a full class tree.

Arrays of objects become List<ItemClass> fields, and the tool automatically inserts the .map((e) => ItemClass.fromJson(e as Map<String, dynamic>)).toList() parsing in fromJson and .map((e) => e.toJson()).toList() in toJson. Nested lists also work — the tool inspects the first non-null element to infer the item type.

Yes. Toggle the json_serializable checkbox and the tool adds the @JsonSerializable() annotation, imports the package, adds a part 'user.g.dart'; directive, and switches fromJson/toJson to delegate to _$UserFromJson and _$UserToJson. You then run flutter pub run build_runner build as usual to generate the actual serialization logic.

Yes. The conversion runs entirely in your browser using JavaScript — nothing is uploaded to any server. Your JSON is never logged or transmitted. The only network requests after page load are the Bootstrap Icons stylesheet and, if you accept the cookie banner, Google Analytics — which sees the fact that a page was visited but never the JSON you paste.

When a JSON value is null, the tool cannot infer a type from the sample, so it uses dynamic. In these cases you should update the field manually with the correct type once you know what shape the API returns. If a field is always null in one sample but populated in others, run the converter against a complete sample — that is the fastest fix.

Dates and enums are not auto-detected — they arrive as Strings or ints from the API. After generating, update the field type to DateTime or your enum, and update fromJson/toJson to parse and serialize. If you use json_serializable, you can add custom JsonConverter classes instead of editing the generated code by hand.

More developer tools