Skip to content
Flutter & Mobile Runs in your browser — nothing uploadedFree · No signup

JSON to Dart Model Generator

Paste an API response and get production-ready Dart classes for your Flutter app: null-safe fields, nested models, lists, fromJson / toJson factories and optional copyWith — generated entirely in your browser.

JSON input

Dart models

class App {
  final int id;
  final String name;
  final double rating;
  final bool isPublished;
  final List<String> tags;
  final Owner owner;
  final List<Track> tracks;

  const App({
    required this.id,
    required this.name,
    required this.rating,
    required this.isPublished,
    required this.tags,
    required this.owner,
    required this.tracks,
  });

  factory App.fromJson(Map<String, dynamic> json) => App(
        id: json['id'] as int,
        name: json['name'] as String,
        rating: (json['rating'] as num).toDouble(),
        isPublished: json['isPublished'] as bool,
        tags: (json['tags'] as List<dynamic>).map((e) => e as String).toList(),
        owner: Owner.fromJson(json['owner'] as Map<String, dynamic>),
        tracks: (json['tracks'] as List<dynamic>).map((e) => Track.fromJson(e as Map<String, dynamic>)).toList(),
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'name': name,
        'rating': rating,
        'isPublished': isPublished,
        'tags': tags,
        'owner': owner.toJson(),
        'tracks': tracks.map((e) => e.toJson()).toList(),
      };

  App copyWith({
    int? id,
    String? name,
    double? rating,
    bool? isPublished,
    List<String>? tags,
    Owner? owner,
    List<Track>? tracks,
  }) =>
      App(
        id: id ?? this.id,
        name: name ?? this.name,
        rating: rating ?? this.rating,
        isPublished: isPublished ?? this.isPublished,
        tags: tags ?? this.tags,
        owner: owner ?? this.owner,
        tracks: tracks ?? this.tracks,
      );
}

class Owner {
  final int id;
  final String email;

  const Owner({
    required this.id,
    required this.email,
  });

  factory Owner.fromJson(Map<String, dynamic> json) => Owner(
        id: json['id'] as int,
        email: json['email'] as String,
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'email': email,
      };

  Owner copyWith({
    int? id,
    String? email,
  }) =>
      Owner(
        id: id ?? this.id,
        email: email ?? this.email,
      );
}

class Track {
  final int id;
  final String title;
  final int durationMs;
  final dynamic artist;

  const Track({
    required this.id,
    required this.title,
    required this.durationMs,
    this.artist,
  });

  factory Track.fromJson(Map<String, dynamic> json) => Track(
        id: json['id'] as int,
        title: json['title'] as String,
        durationMs: json['durationMs'] as int,
        artist: json['artist'],
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'title': title,
        'durationMs': durationMs,
        'artist': artist,
      };

  Track copyWith({
    int? id,
    String? title,
    int? durationMs,
    dynamic artist,
  }) =>
      Track(
        id: id ?? this.id,
        title: title ?? this.title,
        durationMs: durationMs ?? this.durationMs,
        artist: artist ?? this.artist,
      );
}

How to use the JSON to Dart

  1. Paste a JSON object or array (for example an API response) into the input box.
  2. Set the root class name and pick options such as nullable fields or copyWith.
  3. Copy the generated Dart code or download it as a .dart file and add it to your Flutter project.

Features

  • Null-safe Dart 3 output with final fields
  • Nested objects become their own classes; arrays become typed List<T>
  • fromJson / toJson factories and optional copyWith
  • Choose nullable or required fields and the root class name
  • Runs 100% in the browser — your JSON is never uploaded

Frequently asked questions

Does the generated code work with null safety?

Yes. Output targets Dart 3 with sound null safety. Choose 'nullable fields' to make every field optional (Type?) when your API may omit keys, or leave it off to generate required fields.

How are nested objects and lists handled?

Every nested JSON object becomes its own Dart class named after its key (e.g. "address" → Address). Arrays of objects become List<ClassName> and arrays of primitives become List<int>, List<String>, etc.

Should I use this or json_serializable?

For small and medium models, hand-written fromJson/toJson (what this tool generates) has zero build_runner overhead. For very large codebases json_serializable or freezed can be easier to maintain — this tool is a fast way to start either way.