Member-only story
Flutter: Automate Json to Dart Entity Class
Dart JSON Serialisation
2 min readMar 31, 2020
For any API based App, Converting JSON a solid class(es) is a repeating and lengthy task. Here we are going to discuss How can we automate this to decrease our development time and effort.
All the cases We going to use the following JSON as Base case:
{
"employee": {
"name": "Jhon",
"salary": 56000,
"married": false
}
}
Legacy way:
We usually use ‘dart:convert’ .
import 'dart:convert';
Map<String, dynamic> employeeData = jsonDecode(jsonData);//Now We can use this map to access object and initialise classedString employeeName = employeeData['employee']['name'];
Using Web Tools:
A web tool build by javiercbk to automate the process of converting json to class.
All we need to do:
- open https://javiercbk.github.io/json_to_dart/
- Put Json on json Block.
- Give base class name
- Click generate
- validate and Copy to Android studio.