JSON to Dart Class Converter screenshot

JSON to Dart Class Converter

Turn a JSON sample into a Dart class in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.

Privacy First
0 Runs
Updated 2026-11-06
No upload
Instant
No signup

What the JSON to Dart generator does

Each object becomes a class with a const constructor, a fromJson factory and a toJson method, so it works with jsonDecode without code generation. Nested objects call their own fromJson, and a list of objects is mapped element by element. A nullable field stays a required constructor argument typed with a question mark; only a key that is missing from some elements becomes optional, because those are different facts.

How to use it

JSON to Dart Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Dart class below.

Worked example

Input:

{
  "orderId": "A-1001",
  "total": 129.99,
  "currency": "EUR",
  "paid": false,
  "customer": {
    "email": "ada@example.com"
  },
  "lines": [
    {
      "sku": "X1",
      "qty": 2
    },
    {
      "sku": "X2",
      "qty": 1,
      "discount": 0
    }
  ]
}

Output:

// Generated from a JSON sample in the browser by AllTools — nothing was uploaded.
// Rename and adjust to taste; the shape is inferred from one example, not a schema.

class Root {
  final String orderId;
  final double total;
  final String currency;
  final bool paid;
  final Customer customer;
  final List<Line> lines;

  const Root({required this.orderId, required this.total, required this.currency, required this.paid, required this.customer, required this.lines});

  factory Root.fromJson(Map<String, dynamic> json) => Root(
        orderId: json['orderId'] as String,
        total: (json['total'] as num).toDouble(),
        currency: json['currency'] as String,
        paid: json['paid'] as bool,
        customer: Customer.fromJson(json['customer'] as Map<String, dynamic>),
        lines: (json['lines'] as List<dynamic>).map((item) => Line.fromJson(item as Map<String, dynamic>)).toList(),
      );

  Map<String, dynamic> toJson() => {
        'orderId': orderId,
        'total': total,
        'currency': currency,
        'paid': paid,
        'customer': customer,
        'lines': lines,
      };
}

class Customer {
  final String email;

  const Customer({required this.email});

  factory Customer.fromJson(Map<String, dynamic> json) => Customer(
        email: json['email'] as String,
      );

  Map<String, dynamic> toJson() => {
        'email': email,
      };
}

class Line {
  final String sku;
  final int qty;
  final int? discount;

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

  factory Line.fromJson(Map<String, dynamic> json) => Line(
        sku: json['sku'] as String,
        qty: json['qty'] as int,
        discount: (json['discount'] == null ? null : json['discount'] as int),
      );

  Map<String, dynamic> toJson() => {
        'sku': sku,
        'qty': qty,
        'discount': discount,
      };
}

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Dart class; reloading the page discards both.

Each object becomes a class with a const constructor, a fromJson factory and a toJson method, so it works with jsonDecode without code generation. Nested objects call their own fromJson, and a list of objects is mapped element by element. A nullable field stays a required constructor argument typed with a question mark; only a key that is missing from some elements becomes optional, because those are different facts.

Turn a JSON sample into a Dart class in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.

How to use it

JSON to Dart Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Dart class below.

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Dart class; reloading the page discards both.

What to Expect

Best for

  • Converting JSON to Dart class when the data is already on screen.

What this tool keeps

  • Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere.

Sample input

{ "orderId": "A-1001", "total": 129.99, "currency": "EUR", "paid": false, "customer": { "email": "ada@example.com" }, "lines": [ { "sku": "X1", "qty": 2 }, { "sku": "X2", "qty": 1, "discount": 0 } ] }

Sample output

// Generated from a JSON sample in the browser by AllTools — nothing was uploaded. // Rename and adjust to taste; the shape is inferred from one example, not a schema. class Root { final String orderId; final double total; final String currency; final bool paid; final Customer customer; final List<Line> lines; const Root({required this.orderId, required this.total, required this.currency, required this.paid, required this.customer, required this.lines}); factory Root.fromJson(Map<String, dynamic> json) => Root( orderId: json['orderId'] as String, total: (json['total'] as num).toDouble(), currency: json['currency'] as String, paid: json['paid'] as bool, customer: Customer.fromJson(json['customer'] as Map<String, dynamic>), lines: (json['lines'] as List<dynamic>).map((item) => Line.fromJson(item as Map<String, dynamic>)).toList(), ); Map<String, dynamic> toJson() => { 'orderId': orderId, 'total': total, 'currency': currency, 'paid': paid, 'customer': customer, 'lines': lines, }; } class Customer { final String email; const Customer({required this.email}); factory Customer.fromJson(Map<String, dynamic> json) => Customer( email: json['email'] as String, ); Map<String, dynamic> toJson() => { 'email': email, }; } class Line { final String sku; final int qty; final int? discount; const Line({required this.sku, required this.qty, this.discount}); factory Line.fromJson(Map<String, dynamic> json) => Line( sku: json['sku'] as String, qty: json['qty'] as int, discount: (json['discount'] == null ? null : json['discount'] as int), ); Map<String, dynamic> toJson() => { 'sku': sku, 'qty': qty, 'discount': discount, }; }

Frequently asked questions

How do I use the json to dart class converter?

JSON to Dart Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Dart class below.

Is my input uploaded?

No. The text is parsed on this page with JavaScript and is never posted to a server.

Is there a size limit?

Yes: 5 MB per run. Larger input is refused with a message rather than freezing the tab.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.