Member-only story

Flutter: Automate Json to Dart Entity Class

Dart JSON Serialisation

Prafulla Singh
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:

  1. open https://javiercbk.github.io/json_to_dart/
  2. Put Json on json Block.
  3. Give base class name
  4. Click generate
  5. validate and Copy to Android studio.
Source: https://javiercbk.github.io/json_to_dart/

--

--

Prafulla Singh
Prafulla Singh

Responses (2)