Flutter - Convert JSON to Model Class in Dart Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Many times you are receiving API data but it is difficult to create a model class manually for some data that are too big. So we can make a model with just 2 steps. Let's take sample data for which we want to create a model class. { "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }Step-by-Step Implementation Step 1: Just Copy the Data you want to create a model class for. Step 2: Go to this website. Step 3: Paste it and give a name to the model class. Step 4: Copy the Model class and use it in your flutter or dart projects. Model Class Sample 1. With private field Dart class TodoModel { int? _userId; int? _id; String? _title; bool? _completed; TodoModel({int? userId, int? id, String? title, bool? completed}) { if (userId != null) { this._userId = userId; } if (id != null) { this._id = id; } if (title != null) { this._title = title; } if (completed != null) { this._completed = completed; } } int? get userId => _userId; set userId(int? userId) => _userId = userId; int? get id => _id; set id(int? id) => _id = id; String? get title => _title; set title(String? title) => _title = title; bool? get completed => _completed; set completed(bool? completed) => _completed = completed; TodoModel.fromJson(Map<String, dynamic> json) { _userId = json['userId']; _id = json['id']; _title = json['title']; _completed = json['completed']; } Map<String, dynamic> toJson() { final Map<String, dynamic> data = new Map<String, dynamic>(); data['userId'] = this._userId; data['id'] = this._id; data['title'] = this._title; data['completed'] = this._completed; return data; } } 2. Without a Private Field Dart class TodoModel { int? userId; int? id; String? title; bool? completed; TodoModel({this.userId, this.id, this.title, this.completed}); TodoModel.fromJson(Map<String, dynamic> json) { userId = json['userId']; id = json['id']; title = json['title']; completed = json['completed']; } Map<String, dynamic> toJson() { final Map<String, dynamic> data = new Map<String, dynamic>(); data['userId'] = this.userId; data['id'] = this.id; data['title'] = this.title; data['completed'] = this.completed; return data; } } Comment More infoAdvertise with us Next Article Flutter - Convert Formatted String into DateTime Object F flutterwings Follow Improve Article Tags : Flutter Similar Reads Flutter - Load JSON Assets In Flutter, you can load JSON assets using the rootBundle method from the flutter/services package. First, create a new Flutter project by running the following command in your terminal. Step by Step Implementation Step 1: Create a New Project in Android Studio To set up Flutter Development on Andro 3 min read Flutter - Read JSON Data from Assets Folder A JSON object contains data in the form of key/value pair. The keys are strings and the values are the JSON types. Keys and values are separated by a colon. Each entry (key/value pair) is separated by a comma. We will learn how to read the data already stored in your project folder in your app with 3 min read How to Create Private Class in Dart? In this article, we see how we can make the private class in dart. You know how to make the public class in dart. Here is the syntax for making the public class in the dart language. Public class syntax: class class_name { // Body of class } Now we will see how you can make the private class in the 2 min read Flutter - Convert Formatted String into DateTime Object In Dart, there is 1 datatype called DateTime which refers to date and time. It has multiple inbuilt functions which provide us with various details like current date and time. Today we will learn how to convert a formatted string into a DateTime object of dart. For our convenience, we are changing t 2 min read Flutter - Create a Dart Model using Freezed Package In this article, we will learn how to create a dart model automatically with a sample of code using the freezed package. If you are making a large-scale app. You cannot write a model class file for every data you receive from the backend. So here's a simple solution for it where this model will auto 3 min read How to Use 3D Models in Flutter? Flutter has recently developed into the realm of 3D graphics, expanding its capabilities beyond just 2D applications. In this article, we will explore the exciting process of creating 3D objects in Flutter using the flutter_cube library. Steps to Implement 3D Models in FlutterStep 1: Create a new Fl 4 min read Like