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
| JSON | Dart |
|---|---|
"text" | String |
42 | int |
3.14 | double |
true | bool |
[...] | List<T> |
{...} | class with fromJson |
| null or missing | T? |
| unknown | dynamic |
Tips
- Equality: add the
equatablepackage or override==andhashCodefor state management (Bloc, Riverpod). - copyWith: add a
copyWithmethod for immutable updates. - Dates: parse ISO strings with
DateTime.parse(json['createdAt'] as String).
Related tools
Native iOS or Android too? See JSON to Swift and JSON to Kotlin.
How to use the JSON to Dart
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The Dart appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.