JSON to Dart
Turn a JSON sample into typed Dart models with fromJson factories.
Your input
Runs locally. Your input is never uploaded or saved.
Output
Your result will appear here.
When this tool helps
Use this when a Flutter endpoint returns an object and you need an initial model to review. Place the resulting transport model in the data layer, then map it to a domain value if your application needs different rules or names.
How to use this tool
Paste a JSON object, choose a root class name, and generate nested models. Types are inferred from a single sample; review optional fields and nullability against your real API schema.
A worked example
Input
{"id":42,"display-name":"Mira","active":true,"profile":{"city":"Pune"}}Expected result
// Inferred from one sample. Review nullability and optional fields.
class Account {
final int id;
final String display_name;
final bool active;
final AccountProfile profile;
const Account({required this.id, required this.display_name, required this.active, required this.profile});
factory Account.fromJson(Map<String, dynamic> json) => Account(
id: json["id"] as int,
display_name: json["display-name"] as String,
active: json["active"] as bool,
profile: AccountProfile.fromJson(json["profile"] as Map<String, dynamic>),
);
}
class AccountProfile {
final String city;
const AccountProfile({required this.city});
factory AccountProfile.fromJson(Map<String, dynamic> json) => AccountProfile(
city: json["city"] as String,
);
}Choose Account as the root class name. The nested profile becomes its own class. The hyphenated display-name key becomes a valid Dart identifier, while fromJson still reads the original JSON key. Integer and decimal samples produce different numeric types.
Edge cases and limitations
- One response cannot establish which fields are optional. A missing or null value can fail a generated cast; review several real responses and your API schema.
- Empty or mixed-shape lists fall back to List<Object?>. Decide the actual element model before passing data to widgets.
- Use a JSON object at the root, not a top-level array. For a list endpoint, use a representative item to draft its model.
- Very large numeric IDs can lose precision during JavaScript parsing. Represent identifiers as strings when your API contract permits it.
Use the result in your app
Decode a sanitized fixture with Account.fromJson, then add tests for a missing profile, a null name, and an unexpected numeric value. This generator does not emit toJson, equality, copyWith, or serializer annotations.
Keep your workflow private
This utility processes input only in this tab. It does not upload or persist pasted content. Review generated output before using it in a production application.
Need a complete starter? Generate a Flutter project →