JSON Formatter
Format JSON online: beautify messy JSON with 2 or 4 spaces or tabs, sort keys, minify it to one line and find errors. Free, runs in your browser.
Convert JSON to null-safe Dart model classes for Flutter, with fromJson, toJson and an optional copyWith. Free, no sign-up, runs in your browser.
Runs in your browser. Your data never leaves your device.
Paste a JSON response and get Dart classes ready for a Flutter app. Each object becomes a class with a fromJson factory constructor and a toJson method, nested objects and lists are converted for you, and the code follows Dart's sound null safety: a value that is null or missing in your sample becomes a nullable type such as String?. The classes are plain Dart, so they need no extra package and no build step.
Decode the response with jsonDecode from dart:convert and pass the map to fromJson. To send data back, call toJson and encode the result with jsonEncode.
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<User> fetchUser() async {
final res = await http.get(Uri.parse('https://api.example.com/users/1'));
if (res.statusCode != 200) throw Exception('HTTP ${res.statusCode}');
return User.fromJson(jsonDecode(res.body) as Map<String, dynamic>);
}
// Dart object back to JSON
final body = jsonEncode(user.toJson()); Every Dart 3 project runs with sound null safety, so a model has to say which fields can be null. The converter marks a field nullable when it is null or missing in any item of your sample. If your API isn't consistent, tick All fields nullable and check the values where you use them. Code from converters that ignore null safety won't compile in a current Flutter project.
freezed and json_serializable generate fromJson and toJson with build_runner, and freezed adds copyWith, equality and union types. They suit large apps with many models, at the cost of extra packages, annotations and a build step. quicktype is an open source generator for many languages. The classes made here are plain Dart: paste them in and they work. Tick copyWith if you update models in your state management.
In clean architecture the class made from JSON is the model in the data layer, and the entity is the plain class your app logic uses. Many apps use the model directly. If you keep both, generate the model here and map it to the entity in your repository. VS Code and Android Studio also have extensions that make Dart classes from JSON inside the editor.
One that writes null-safe code which compiles on current Flutter without extra packages. This converter does that and adds copyWith when you ask. For large apps that also want generated equality and union types, use freezed.
Yes. Fields that are null or missing in your sample get a nullable type, and you can make every field nullable with one tick.
No. The classes include their own fromJson and toJson. Use freezed or json_serializable only if your project already uses build_runner.
Yes. The converter reads every item of the array, so a field that appears in only some items becomes nullable.
No. Everything runs in your browser.
Format JSON online: beautify messy JSON with 2 or 4 spaces or tabs, sort keys, minify it to one line and find errors. Free, runs in your browser.
Check if JSON is valid and see the exact line and column of any error, with a hint on how to fix it. A free online JSON validator in your browser.
Paste JSON and get Kotlin data classes for Android, with kotlinx.serialization, Gson or Moshi names, nullable fields and defaults. Free, in your browser.
Turn JSON into Swift Codable structs or classes, with CodingKeys for snake_case keys. Free JSON to Swift converter for iOS and macOS apps.