Free tool
JSON to Dart converter
Paste your JSON and get ready-to-use, null-safe Dart model classes for your Flutter app. Nested objects and lists become their own classes.
Dart model
class Shop {
const Shop({
required this.id,
required this.name,
required this.rating,
required this.isOpen,
required this.tags,
required this.address,
required this.menu,
});
final int id;
final String name;
final double rating;
final bool isOpen;
final List<String> tags;
final Address address;
final List<MenuItem> menu;
factory Shop.fromJson(Map<String, dynamic> json) {
return Shop(
id: json['id'] as int,
name: json['name'] as String,
rating: (json['rating'] as num).toDouble(),
isOpen: json['isOpen'] as bool,
tags: (json['tags'] as List<dynamic>).map((e) => e as String).toList(),
address: Address.fromJson(json['address'] as Map<String, dynamic>),
menu: (json['menu'] as List<dynamic>).map((e) => MenuItem.fromJson(e as Map<String, dynamic>)).toList(),
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'rating': rating,
'isOpen': isOpen,
'tags': tags,
'address': address.toJson(),
'menu': menu.map((e) => e.toJson()).toList(),
};
}
}
class Address {
const Address({
required this.city,
required this.postcode,
});
final String city;
final String postcode;
factory Address.fromJson(Map<String, dynamic> json) {
return Address(
city: json['city'] as String,
postcode: json['postcode'] as String,
);
}
Map<String, dynamic> toJson() {
return {
'city': city,
'postcode': postcode,
};
}
}
class MenuItem {
const MenuItem({
required this.id,
required this.title,
required this.price,
this.isNew,
});
final int id;
final String title;
final double price;
final bool? isNew;
factory MenuItem.fromJson(Map<String, dynamic> json) {
return MenuItem(
id: json['id'] as int,
title: json['title'] as String,
price: (json['price'] as num).toDouble(),
isNew: json['isNew'] as bool?,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'title': title,
'price': price,
'isNew': isNew,
};
}
}
Your JSON never leaves your device: the conversion runs entirely in your browser.
How to use it
- Paste a JSON response from your API into the left box, or edit the example.
- Set the class name for the top-level object, for example
UserorProduct. - Choose options: toJson() to send data back to an API, copyWith() for immutable state updates, and All fields nullable if your API sometimes leaves fields out.
- Copy the code or download it as a
.dartfile and add it to your project.
Using the model in Flutter
Decode the response with jsonDecode and pass it to the generated fromJson factory:
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<Shop> fetchShop() async {
final response = await http.get(Uri.parse('https://api.example.com/shop/42'));
if (response.statusCode != 200) throw Exception('Failed to load shop');
return Shop.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
}How types are detected
- Whole numbers become
int, decimals becomedouble. If a list mixes both, it usesdouble. - Nested objects become their own class, named after the key (
address→Address). - Lists of objects get a singular class name (
categories→List<Category>). All items are merged, so a field missing from some items becomes nullable. - null values and empty lists become
dynamic, because their real type can’t be known from the sample. - Keys are converted to camelCase field names (
user_name→userName), and Dart keywords get a suffix (class→classValue).
FAQ
Does it support null safety? Yes. The generated code targets Dart 3 with sound null safety and passes dart analyze with no issues.
Do I need json_serializable or build_runner? No. The classes are plain Dart with hand-written fromJson and toJson, so there is no code generation step and no extra packages.
Is my data safe? Yes. Nothing is uploaded: the JSON is converted by JavaScript in your browser.
Want to see these models in a real app? Browse my Flutter projects with full source code.