Developer Tools

JSON to Dart

Generate Flutter & Dart model classes with fromJson factory constructors and toJson serialization methods.

  • Runs in your browser
  • Free, no signup
Target Language:
JSON Input 12 lines
Dart Output 16 lines
class Profile {
  final String bio;
  final int reputation;

  Profile({
    required this.bio,
    required this.reputation,
  });

  factory Profile.fromJson(Map<String, dynamic> json) {
    return Profile(
      bio: json['bio'] as String,
      reputation: json['reputation'] as int,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'bio': bio,
      'reputation': reputation,
    };
  }
}

class Root {
  final int id;
  final String name;
  final String email;
  final bool isAdmin;
  final List<String> roles;
  final Profile profile;

  Root({
    required this.id,
    required this.name,
    required this.email,
    required this.isAdmin,
    required this.roles,
    required this.profile,
  });

  factory Root.fromJson(Map<String, dynamic> json) {
    return Root(
      id: json['id'] as int,
      name: json['name'] as String,
      email: json['email'] as String,
      isAdmin: json['is_admin'] as bool,
      roles: ((json['roles'] as List<dynamic>?)?.map((e) => e.toString()).toList() ?? []),
      profile: json['profile'] != null ? Profile.fromJson(json['profile'] as Map<String, dynamic>) : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'email': email,
      'is_admin': isAdmin,
      'roles': roles,
      'profile': profile.toJson(),
    };
  }
}

Your files are processed locally in your browser and are not uploaded to our server.

Building Flutter applications requires robust Dart model classes that can serialize and deserialize JSON payloads. This tool transforms any JSON object or array into clean, null-safe Dart classes equipped with factory fromJson and toJson methods.

The generated classes include required named constructor arguments, type-safe casting (as String, as int), safe list mappings, and recursive nested model instantiation. Everything runs in-browser without third-party server calls.

How to use this tool

  1. Paste your JSON payload into the editor or click "Load Sample".
  2. Select your serialization style: "With fromJson & toJson" or "Simple Immutable Model".
  3. Name your root model class (e.g. UserModel or ProductResponse).
  4. Copy or download the generated .dart file directly into your Flutter lib/models directory.

Sound Null-Safety by Design

The generated Dart code adheres to Dart's sound null-safety system. Properties that cannot be verified as non-null are given nullable type annotations (T?) and safe null-coalescing operations during deserialization.

Frequently asked questions

Can I use this code directly in a Flutter app?

Yes. The generated classes use standard Dart and require no external packages like build_runner or json_serializable, making them immediately usable in any Flutter project.