Skip to content
XUtilHub

JSON to Dart Class Generator for Flutter

Convert JSON to null-safe Dart classes with fromJson and toJson for Flutter. Handles nested lists, int vs double, nullable fields and Dart keywords.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Code

About the JSON to Dart

Generate null-safe Dart model classes with fromJson factories and toJson methods, ready for Flutter apps. Number handling is safe: a JSON 5 decodes correctly into a double field.

Key features

  • Null-safe Dart classes with final fields
  • fromJson factory constructors, nested lists included
  • toJson methods (optional)
  • Safe number handling: int values decode into double fields
  • camelCase fields mapped to original JSON keys
  • No build_runner or code generation step needed

Flutter-ready Dart models

Every Flutter app that talks to an API needs model classes with fromJson and toJson. Writing them by hand, with the casts that null safety demands, is repetitive and easy to get wrong. Paste JSON and get complete, null-safe classes in seconds.

Example

{ "id": 1001, "price": 9.5, "tags": ["gift"], "customer": { "name": "Ada" }, "coupon": null }
class Order {
  final int id;
  final double price;
  final List<String> tags;
  final Customer customer;
  final dynamic coupon;

  const Order({
    required this.id,
    required this.price,
    required this.tags,
    required this.customer,
    this.coupon,
  });

  factory Order.fromJson(Map<String, dynamic> json) => Order(
        id: json['id'] as int,
        price: (json['price'] as num).toDouble(),
        tags: (json['tags'] as List<dynamic>).map((e0) => e0 as String).toList(),
        customer: Customer.fromJson(json['customer'] as Map<String, dynamic>),
        coupon: json['coupon'],
      );
}

Using the models

final res = await http.get(Uri.parse('https://api.example.com/orders/1001'));
final order = Order.fromJson(jsonDecode(res.body) as Map<String, dynamic>);

Type mapping

JSONDart
"text"String
42int
3.14double
truebool
[...]List<T>
{...}class with fromJson
null or missingT?
unknowndynamic

Tips

  • Equality: add the equatable package or override == and hashCode for state management (Bloc, Riverpod).
  • copyWith: add a copyWith method for immutable updates.
  • Dates: parse ISO strings with DateTime.parse(json['createdAt'] as String).

Native iOS or Android too? See JSON to Swift and JSON to Kotlin.

How to use the JSON to Dart

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The Dart appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

Do I need json_serializable or build_runner?

No. The generated fromJson and toJson are plain Dart, so they work immediately. You can switch to json_serializable later if you prefer annotations.

Why (json['price'] as num).toDouble()?

JSON doesn't distinguish 5 from 5.0, so dart:convert decodes 5 as an int. Casting directly to double would throw; going through num handles both.

How are Dart keywords handled?

Keys that are Dart reserved words, such as class or default, become classValue or defaultValue, while the JSON key stays the same in fromJson and toJson.

Does it work with Flutter's http or dio?

Yes. Decode the response body with jsonDecode and pass the map to fromJson (dio already decodes JSON for you).

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools