
Paste JSON data to generate Dart model classes with fromJson() and toJson() for Flutter. 100% local processing, no data uploaded.
Dart is the programming language behind Flutter, Google's cross-platform UI framework for building mobile, web, and desktop apps from a single codebase. Almost every Flutter app communicates with REST APIs that return JSON data, and each JSON response needs a corresponding Dart data model class with serialization methods to convert between JSON maps and typed Dart objects. Writing these classes by hand is tedious: a single API response with 10 fields and 3 nested objects can mean 150+ lines of boilerplate code, including the constructor, fromJson factory, toJson method, and field mappings. This tool reads your JSON input and generates complete, ready-to-use Dart classes with all serialization logic included.
When you paste JSON into the converter, it analyzes the structure and produces the following components for each class:
Suppose you have the following JSON response from a user profile API:
{ "user_id": 42, "full_name": "Jane Doe", "is_active": true, "tags": ["flutter", "dart"], "address": { "city": "Berlin", "zip_code": "10115" } }
The converter generates two Dart classes. The User class references an Address class for the nested object. Field names are converted from snake_case to Dart camelCase: user_id becomes userId, full_name becomes fullName, and @JsonKey annotations preserve the original JSON keys. The generated fromJson method reads each field with proper null-safety checks, and toJson serializes back to the original key names. List fields are generated as List<String> with proper JSON array parsing.
Dart's null safety feature, introduced in Dart 2.12, makes types non-nullable by default. This means a String field cannot hold null unless you explicitly declare it as String?. The converter analyzes your JSON to determine which fields are optional: if a field is missing from the JSON or has a null value, it is generated as nullable (with the ? suffix). Required fields that always appear in the API response are generated as non-nullable with the required keyword in the constructor. This ensures compile-time null checking and eliminates an entire class of runtime null reference errors.
Paste your JSON data into the input area. Enter a root class name in the designated field. Toggle options for null safety, @JsonKey annotations, and json_serializable compatibility. Click Convert to generate the Dart code. Copy the output and paste it into your Flutter project. If you use json_serializable, add the json_annotation and json_serializable packages to your pubspec.yaml, then run flutter pub run build_runner build to generate the .g.dart files.
Null Safety is a Dart feature introduced in Dart 2.12 that prevents null reference errors at compile time. Types are non-nullable by default, meaning a String field cannot hold null unless you explicitly declare it as String? (nullable). The converter analyzes your JSON and marks fields as nullable when they are missing or null in the input, and non-nullable when they always appear.
fromJson is a factory constructor that takes a Map<String, dynamic> from a decoded JSON response and creates a typed Dart instance. toJson is an instance method that converts the Dart object back to a Map, which you can pass to jsonEncode for API requests. Together they form the standard JSON serialization pattern in Dart and Flutter.
No. The generated code includes hand-written fromJson and toJson methods that work standalone without any packages. However, for larger projects with many models, json_serializable is recommended because it auto-generates serialization code via build_runner, reducing maintenance when API responses change. If you use it, add @JsonSerializable() and let the tool generate .g.dart files.
Each nested JSON object gets its own Dart class. The parent class references the child class by type, creating a clean, type-safe hierarchy. For example, if your JSON has an address object inside a user object, the converter generates a User class with an Address field, and a separate Address class with its own fromJson and toJson methods. Deeply nested structures produce multiple classes automatically.
The converter transforms snake_case JSON keys like full_name into Dart camelCase field names like fullName. A @JsonKey(name: 'full_name') annotation is added so the serialization methods know which JSON key maps to which Dart field. This follows the Dart style guide convention of using camelCase for variable names while preserving the original API key names.
JSON arrays are converted to Dart List types. An array of strings becomes List<String>, an array of numbers becomes List<int> or List<double>, and an array of objects becomes List<YourClass> where YourClass is generated from the first element of the array. The fromJson method parses each element using List.map and casts appropriately.
For standalone generated code: add json_annotation under dependencies if you use @JsonKey annotations. For json_serializable workflow: add json_annotation and json_serializable under dependencies, and build_runner under dev_dependencies. Run flutter pub get, then flutter pub run build_runner build to generate .g.dart files.