Convert JSON to Dart
fromJson, toJson,
null safety, copyWith.
Free JSON to Dart converter for Flutter. Generates model classes with fromJson, toJson, null safety and copyWith. Nested objects become separate classes. Runs entirely in your browser — no upload, no account.
Three steps — paste your JSON and drop the class into your Flutter project.
Paste a sample JSON response from your API — a single object or an array. The converter uses the structure and values to infer Dart types: int, double, String, bool, List and nested classes. Use a real response with non-null values for the most accurate type inference.
Enter the root class name (e.g. User, Product, ApiResponse). Toggle null safety for Dart ≥ 2.12 projects, include toJson for serialisation, and add copyWith if you use immutable state management with Provider, Riverpod or Bloc.
Click Generate and copy the Dart code directly into your project — or download as a .dart file. The class is ready to use: paste it into your models folder, import it, and call ClassName.fromJson(response.data) immediately.
How the converter maps JSON value types to Dart types.
Dart is a strongly-typed language — every field in a model class needs an explicit type. JSONshift infers Dart types from the JSON values in your sample: JSON integers become int, floating-point numbers become double, strings become String, booleans become bool, and nested objects become a new Dart class with a PascalCase name derived from the key.
Null safety (introduced in Dart 2.12) changes how optional fields are handled. A field whose sample value is null in the JSON becomes a nullable type like String? — it can safely be absent from the API response. Fields with non-null values are typed without the ? and are treated as required. This maps directly to how Dart's type system distinguishes between must be present and may be absent.
The fromJson factory constructor uses json['key'] as Type for primitives and NestedClass.fromJson(json['key']) for nested objects. The toJson method returns a Map<String, dynamic> with nested objects serialised via their own toJson() — making the class compatible with json_serializable conventions and directly usable with dio, http and Dart's jsonEncode.
Common Flutter development workflows where model generation saves time.
Every Flutter app that fetches data from a REST API needs model classes to deserialise the JSON response. Generating fromJson from the actual API response — rather than writing the class by hand — eliminates typos in key names and missing fields.
Firestore documents are JSON objects. Generating a Dart model from a sample document snapshot gives you a typed class with fromJson and toJson that maps directly to Firestore's DocumentSnapshot.data() and doc.set(model.toJson()) pattern.
Provider, Riverpod and Bloc all work best with immutable model classes. The copyWith method generated by JSONshift follows the same pattern as Flutter's own ThemeData and TextStyle — making your models first-class citizens in any state management architecture.
When building a proof of concept or a new feature, generating model classes from mock JSON lets you start writing UI code immediately — without setting up json_serializable, running build_runner, or waiting for code generation. Ship the prototype, refine the model later.
What each setting produces in the Dart output.
| Option | Values | What it does |
|---|---|---|
| Root class name | Any valid Dart identifier | The name of the top-level Dart class. Use PascalCase — e.g. UserProfile, ProductDetail. Nested object classes are derived automatically from the key name: a key address produces a class named Address. |
| Null safety | Enabled · Disabled | Enabled marks nullable fields with ? — required for Dart ≥ 2.12 and all current Flutter versions. Disabled generates pre-null-safety code where all fields are non-nullable — use this for legacy projects that haven't migrated yet. |
| toJson method | Include · Omit | Include generates a Map<String, dynamic> toJson() method for serialisation — required for POST requests, Firestore writes and local storage. Omit generates a read-only model with only fromJson — suitable when you only ever receive data from the API. |
| copyWith method | Include · Omit | Include generates a copyWith() method that returns a new instance with specified fields replaced — the standard pattern for immutable state in Flutter. Omit keeps the class minimal if you don't use immutable state management. |
| Field modifiers | final · var | final makes all fields immutable after construction — the recommended approach for Flutter models used with state management. var makes fields mutable — useful for form models or when you need to update individual fields after instantiation. |
Other free converters you might need in your Flutter workflow.
Dart models generated
in your browser. No upload.
The entire class generation runs in JavaScript locally. Your JSON API response is parsed and traversed in your browser — it is never transmitted to any server, never stored, and gone the moment you close the tab.
The generated code follows Dart conventions: PascalCase class names, camelCase field names, factory constructors for fromJson, and Map<String, dynamic> for toJson — compatible with dio, http, json_serializable conventions and Flutter's own state management patterns.
