Loading JSON to Dart Converter...
Please wait a moment

How to Convert JSON to Dart Classes - Step by Step Guide

Step 1

Input Your JSON Data

Start by adding your JSON data that needs to be converted to Dart classes. The tool will analyze the structure and generate appropriate Flutter-ready Dart code:

•
Paste JSON: Copy and paste your JSON data directly into the editor
•
Upload a file: Click Upload to pick a .json or .txt file from your computer
•
Try sample data: Click Sample to load an example user profile with posts. Working from XML instead? Use the XML to Dart converter.
Step 2

Pick a Root Class Name

There is one setting: the Class Name box above the editor. It names the top-level class (Root by default). Everything else is worked out from the JSON itself:

•
Nested classes: each nested object gets a class named after its key, and items in a list like orders become Order
•
Null safety: a field is nullable only when it is missing or null somewhere in your data
•
Top-level lists: a JSON array of objects gives one class for the items, and the header comment shows how to map the list
Step 3

Read the Generated Classes

For this input, id becomes int, price becomes double, and the second order's qty becomes int? because the first order doesn't have it:

{"id":8901240544102066246,"name":"Ana","price":14.50,"tags":["new"],"orders":[{"sku":"A1"},{"sku":"B2","qty":2}]}
class Order {
  final String sku;
  final int? qty;

  const Order({
    required this.sku,
    this.qty,
  });

  factory Order.fromJson(Map<String, dynamic> json) {
    return Order(
      sku: json['sku'] as String,
      qty: json['qty'] as int?,
    );
  }
  // ...toJson()
}

Copy the code or download it as a .dart file, then read your data with Root.fromJson(jsonDecode(text) as Map<String, dynamic>).

Frequently Asked Questions

Do I need json_serializable or build_runner?

No. The classes are plain Dart with hand-written fromJson and toJson methods, so there is no code generation step and no package to add. You only need dart:convert, which ships with Dart, to call jsonDecode.

How does it decide between int, double and String?

It looks at how each number is written in your JSON. Whole numbers like 42 or 8901240544102066246 become int, numbers with a decimal point or exponent like 14.50 or 1.0 become double, and a list that mixes 1 and 2.5 becomes List<double>. Quoted values such as "00501" stay String, so leading zeros are never lost. Doubles are read with (x as num).toDouble(), so a whole number in a double field still works.

What happens when list items have different fields?

Every item in a list is looked at, not just the first one. Fields that only some items have, or that are null in some of them, become nullable (for example int? or String?) and are left out of the required constructor parameters. If the same field holds a number in one item and text in another, it becomes dynamic.

What does it do with keys that are not valid Dart names?

Keys are turned into camelCase field names, while fromJson and toJson keep using your original key. Dashes and spaces are dropped (first-name becomes firstName), names starting with a digit get a field prefix, Dart keywords such as class or default get a Value suffix, and keys that end up with the same name are numbered. Nested classes that would clash with Dart types like List or Map are renamed, for example ListModel.

Will long IDs lose digits?

Not in the generated code or on the Dart VM. A value like 8901240544102066246 becomes an int field, and Dart ints are 64-bit on mobile, desktop and server. Flutter web is the exception: it runs on JavaScript numbers, so the output adds a note when your JSON has ints larger than 2^53.

Is my JSON uploaded anywhere?

No. The classes are generated in your browser and the JSON never leaves your device.