JSON to Dart Converter
Generate dependency-free Dart model classes from a JSON object or an array of object samples. The converter merges every sampled array item, creates nested classes, preserves original JSON keys and produces sound null-safe field types with a factory fromJson constructor. Add toJson methods when you need output compatible with jsonEncode. Your sample and generated code stay in this browser and are never uploaded or placed in the URL.
How it works
-
1
Paste a representative sample
Use one JSON object or an array of objects. Multiple items help reveal missing, nullable and mixed-type fields.
-
2
Choose Dart options
Name the root class, decide whether every field should be nullable and include toJson methods if needed.
-
3
Review and export
Inspect the inferred classes, then copy the code or download a local models.dart file.
How JSON becomes null-safe Dart models
Dart’s official dart:convert documentation explains that jsonDecode() produces JSON-compatible values such as numbers, strings, Booleans, nulls, lists and string-keyed maps. A model class is not directly JSON-encodable, but jsonEncode() can call its toJson() method. This converter generates that manual serialization pattern without adding json_serializable annotations or package dependencies.
Suppose a sample contains a user with a nested address. The generated User has final fields and a named-parameter constructor. User.fromJson(Map<String, Object?> json) casts scalar values and calls UserAddress.fromJson() for the nested object. If address is absent or null in any sampled object, its type becomes UserAddress? and the factory checks for null before constructing it. When toJson is enabled, nested models are converted recursively into maps that jsonEncode() accepts.
| JSON observation | Generated Dart type |
|---|---|
| Whole number | int |
| Fractional number | double |
| Whole and fractional samples | num |
| Text | String |
| Boolean | bool |
| Nested object | A generated model class |
| Consistent array | List<T> |
| Empty or incompatible nested array | List<Object?> |
| Null-only or conflicting values | Object? |
The converter examines every object in a root array rather than trusting only the first item. A field becomes nullable when it is missing from one item or explicitly null. You can also make every field nullable when the real API is less predictable than the sample. The Dart null-safety guide notes that types are non-nullable by default and need ? to accept null.
Identifier handling and inference limits
JSON keys do not have to be valid Dart members. Punctuation is removed, words are converted to lowerCamelCase, reserved keywords receive a safe suffix and collisions receive deterministic numeric suffixes. The original key remains unchanged in json['original-key'] and in the toJson() map. Nested class names use their full path so unrelated address objects do not silently become one class.
One sample cannot prove an API contract. JSON strings are not automatically dates, UUIDs or enums, and an empty array provides no element type. Duplicate object member names are also not round-trip safe: JSON parsers commonly retain the last value. Review the generated models against the API documentation or schema before using them in production. The tool limits input, nesting, inferred declarations and output size to keep browser work bounded.
Frequently Asked Questions
No. Parsing, inference, code generation, copying and downloading happen in your browser. The JSON and generated Dart are not sent to our servers or placed in the URL.
Yes. Flutter uses Dart, so these dependency-free classes can be used in a Flutter project. Review the inferred types against the real API contract first.
No. It generates manual fromJson and optional toJson methods with no package or build-runner dependency.
A field observed as null or absent becomes nullable. You can choose to make every generated field nullable when the sample is not representative.
No. The result reflects only observed values. Use multiple object samples and compare the result with the provider’s schema or documentation.
Related Tools
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.
Tool available in other languages
- JSON till Dart-konverterare [SV]
- محول JSON إلى Dart [AR]
- Convertisseur JSON vers Dart [FR]
- Konverter JSON ke Dart [ID]
- JSON-in-Dart-Konverter [DE]
- JSON to Dart 변환기 [KO]
- JSON-naar-Dart-converter [NL]
- JSONからDartへの変換ツール [JA]
- ตัวแปลง JSON เป็น Dart [TH]
- Konwerter JSON na Dart [PL]
- Conversor de JSON a Dart [ES]
- Trình chuyển JSON sang Dart [VI]
- Conversor de JSON para Dart [PT]
- Convertitore da JSON a Dart [IT]
- Конвертер JSON в Dart [RU]
- JSON'dan Dart'a Dönüştürücü [TR]
- JSON 转 Dart 工具 [ZH]