What is JSON → Dart?
Generate Dart model classes from JSON data with json_serializable and Freezed support.
Nested objects become their own model classes with fromJson and toJson helpers. Output updates as you type, and everything runs in your browser.
Features
- Generate Dart classes from JSON
- json_serializable and Freezed support
- fromJson and toJson method generation
- Nullable type handling
- Nested model generation
- Copy generated code to clipboard
How to use JSON → Dart
- Paste your JSON. Enter a sample JSON object.
- Select style. Choose plain Dart, json_serializable, or Freezed.
- Copy Dart code. Get Flutter-ready model classes.
Examples
Generating Dart model classes
A small user record with a nested address, generated with the default settings. Trimmed to the first 38 lines (the Root class); an Address class is generated the same way.
Input
{
"id": 1,
"name": "Ada Lovelace",
"email": "ada@example.com",
"active": true,
"tags": ["admin", "dev"],
"address": { "city": "London", "zip": "EC1A" }
}Output
// To parse this JSON data, do
//
// final root = rootFromJson(jsonString);
import 'package:json_annotation/json_annotation.dart';
import 'dart:convert';
part 'root.g.dart';
Root rootFromJson(String str) => Root.fromJson(json.decode(str));
String rootToJson(Root data) => json.encode(data.toJson());
@JsonSerializable()
class Root {
@JsonKey(name: "id")
int id;
@JsonKey(name: "name")
String name;
@JsonKey(name: "email")
String email;
@JsonKey(name: "active")
bool active;
@JsonKey(name: "tags")
List<String> tags;
@JsonKey(name: "address")
Address address;
Root({
required this.id,
required this.name,
required this.email,
required this.active,
required this.tags,
required this.address,
});
factory Root.fromJson(Map<String, dynamic> json) => _$RootFromJson(json);Frequently asked questions
What serialization options are available?
Plain Dart, json_serializable (@JsonSerializable), or Freezed (@freezed) models.
Does it support Flutter?
Yes. Works with Flutter, Dio, http package, and any Dart project.
