JSON to Dart

Input
Output

JSON to Dart

Paste a JSON sample, such as an API response, and Bracely writes Dart classes for Flutter for it. Each object becomes a Dart class with final fields and a const constructor, ready for your Flutter models.

Example: a product list for a Flutter app

Products from a shop API, one of them on sale. Each object becomes a Dart class with final fields and a const constructor; sale_price, missing from one product, becomes nullable and isn't required, and snake_case keys become camelCase fields:

Input

[
  {
    "id": "KB-01",
    "title": "Keyboard",
    "price": 2499,
    "sale_price": 1999,
    "in_stock": true,
    "images": [
      "kb-front.jpg",
      "kb-side.jpg"
    ]
  },
  {
    "id": "MS-02",
    "title": "Mouse",
    "price": 799,
    "in_stock": false,
    "images": []
  }
]

Output

class Product {
  final String id;
  final String title;
  final int price;
  final int? salePrice; // json: "sale_price"
  final bool inStock; // json: "in_stock"
  final List<String> images;

  const Product({
    required this.id,
    required this.title,
    required this.price,
    this.salePrice,
    required this.inStock,
    required this.images,
  });
}

How do I use the JSON to Dart?

  1. Paste a JSON sample.
  2. Set the root type name, for example Order.
  3. Copy the Dart code into your project.

What does the JSON to Dart do?

  • Final, typed fields
  • required named parameters
  • Nullable types for optional fields
  • Nested objects become their own named types
  • 20 other languages from the same sample, including TypeScript

When to use the JSON to Dart

Flutter apps need a model class for each API response, and writing them field by field is the slowest part of wiring up a new screen. Paste a real response and copy classes with every field typed, ready to fill from the decoded JSON.

Each object becomes a class with final fields and a const constructor with named parameters. Fields that are always present are required; a field missing from some items, like sale_price in the example, becomes nullable and isn't required. snake_case keys become camelCase fields, with the original key in a comment. Whole numbers are int, decimals double and lists List<T>.

Frequently asked questions

Does it write fromJson and toJson?
No, only the model classes. Add a factory Product.fromJson(Map<String, dynamic> json) by hand using the keys in the comments, or annotate the class for json_serializable and run build_runner.
Why is a field dynamic?
Its values in the sample have different types. dynamic accepts anything; replace it with the type you expect once you know it.
How does it pick Dart types?
From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
Can I generate other languages?
Yes. Change Language to any of the others: TypeScript, Go, Python, Pydantic, Java, C#, Kotlin, Swift, Rust, Scala, Ruby, PHP, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
Is my data uploaded?
No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.

More JSON tools

Bracely has 108 JSON tools in one page. Related ones:

Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram