Convert JSON to Dart models online

What online JSON-to-Dart converters generate, where type inference from one sample goes wrong, and when hand-written or locally generated models are the better choice.

Online JSON-to-Dart converters take a sample JSON payload and produce Dart class definitions, usually with constructors and methods for decoding and encoding. They can save setup time when you are wiring an API into a Flutter or Dart project. This review explains what the conversion produces, where it can mislead you, and when another approach works better. It covers the general category of tools. No specific converter was tested for this article, so it makes no claims about any named tool's features, accuracy or data handling.

Is an online converter suitable for your use?

The main benefit is speed. A converter turns a nested payload into typed classes in seconds, and typed classes catch field-name typos and type mismatches at compile time instead of at runtime.

The main tradeoff is that the tool can only see the one sample you give it. A single sample cannot show which fields are optional, which numbers can have decimals, or what type a null field holds. The output is a first draft that you need to review against the API's actual contract.

A converter is a reasonable fit when:

  • You have a representative, non-sensitive sample payload.
  • You plan to review and adjust the generated types.
  • The schema is fairly stable, so a one-time draft will not go stale quickly.

Other approaches are usually better in these situations:

  • One-off scripts or tiny payloads: decoding to Map<String, dynamic> with dart:convert, or writing a short class by hand, is often simpler.
  • Long-lived projects with evolving APIs: annotation-based generation with the json_serializable package (optionally with freezed), run through build_runner, keeps models regenerable inside your codebase. You do not have to repeatedly paste output from a website.
  • Payloads with credentials, tokens or personal data: avoid pasting them into any web tool unless its data handling is documented and acceptable to you. Generate locally or use a redacted sample instead.

What the conversion actually changes

This is code generation, not a visual text effect. Nothing is reversed, mirrored or restyled with Unicode lookalike characters. Your JSON is left unchanged. The tool reads its structure and writes new Dart source code that describes that structure. In practice, the output usually includes:

  • One class per JSON object. Nested objects become their own classes, with names derived from their keys.
  • One field per key, with a type inferred from the sample value.
  • Key names converted to Dart conventions, such as user_name becoming userName, while the original key is kept as the lookup string.
  • A fromJson factory constructor that reads a Map<String, dynamic>, and often a toJson method that writes one back.

Type inference follows the JSON value it sees. The mapping below shows the usual pattern and where it breaks down.

JSON value in sample | Likely Dart type | Risk
"text" | String | Dates and IDs stay strings unless you convert them yourself
42 | int | Fails at runtime if a later response sends 42.5
9.5 | double | Safe for whole numbers only if decoded through num
true | bool | Low
["a", "b"] | List<String> | Mixed-type arrays may need List<dynamic>
[] | List<dynamic> or a guess | Element type is unknown from an empty array
null | dynamic, Object? or a guess | Real type is unknown from the sample
{ ... } | New class | Duplicate or generic key names can produce clashing class names

Here is an illustrative input with a hand-written model following the common pattern. It is not the output of any particular tool. Two decisions in it are ones a converter cannot make from this sample alone. First, last_login is typed as a nullable String, because the sample's null reveals nothing about its type. Second, score is decoded through num, so both 9 and 9.5 work.

{
  "id": 42,
  "user_name": "ada",
  "score": 9.5,
  "tags": ["admin", "beta"],
  "address": { "city": "Austin", "zip": "78701" },
  "last_login": null
}
class User {
  final int id;
  final String userName;
  final double score;
  final List<String> tags;
  final Address address;
  final String? lastLogin;

  User({
    required this.id,
    required this.userName,
    required this.score,
    required this.tags,
    required this.address,
    this.lastLogin,
  });

  factory User.fromJson(Map<String, dynamic> json) => User(
        id: json['id'] as int,
        userName: json['user_name'] as String,
        score: (json['score'] as num).toDouble(),
        tags: List<String>.from(json['tags'] as List),
        address: Address.fromJson(json['address'] as Map<String, dynamic>),
        lastLogin: json['last_login'] as String?,
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'user_name': userName,
        'score': score,
        'tags': tags,
        'address': address.toJson(),
        'last_login': lastLogin,
      };
}

class Address {
  final String city;
  final String zip;

  Address({required this.city, required this.zip});

  factory Address.fromJson(Map<String, dynamic> json) => Address(
        city: json['city'] as String,
        zip: json['zip'] as String,
      );

  Map<String, dynamic> toJson() => {'city': city, 'zip': zip};
}

Check these points in any generated output:

  • Null safety: modern Dart requires sound null safety. Fields that can be missing or null must be nullable or have defaults, or decoding will throw.
  • Optional keys: a key that appears in your sample may be absent in other responses, and the generator cannot tell.
  • Identifier problems: keys that are Dart reserved words, start with digits, or contain symbols need renaming. The original key string must still be used for lookup.
  • Number handling: decide whether each numeric field is int, double or num, based on the API documentation rather than one sample.

Will the result stay usable after copying or sharing?

Generated Dart is ordinary source text, so it is not affected by the problems that styled Unicode text has. Screen readers and editors treat it as normal characters, identifiers stay searchable, and reading order is unaffected. The practical risks come from the path the code takes between the tool and your project:

  • Rich-text editors, chat apps and word processors can replace straight quotes with curly ones or change indentation, which breaks compilation. Paste directly into your code editor.
  • Run dart format to normalize layout, then dart analyze to catch type and null-safety errors before relying on the code.
  • Test fromJson against several real responses, including ones with missing or null fields, not just the sample you converted.
  • If you share models with a team, commit the reviewed source. A pasted-in snippet with no record of how it was produced is harder to regenerate when the API changes.

Non-ASCII content in JSON string values, such as accented or right-to-left text, ends up in your runtime data, not in the generated class structure. Display issues with that text belong to your UI layer, not to the converter.

Gaps in this review

No specific online converter was tested, so this article cannot compare tools on output quality, supported options such as freezed or json_serializable annotations, handling of edge cases, or speed. No documented privacy or retention terms for any tool were reviewed. A tool's appearance or marketing language is not evidence of how it stores pasted data, so check its published policy, or use local generation for anything sensitive.