object to json flutter code example

Example 1: dart map to json string

import 'dart:convert';
...
json.encode(data); // JSON.encode(data) in Dart 1.x

Example 2: flutter generate json files

flutter packages pub run build_runner build

Example 3: flutter json to class

//insideclass
ClassName.fromJson(Map<String, dynamic> json) {
    variable1 = json['variable11'];
    variable2 = json['variable12'];
    variable3 = json['variable13']['variable14'];
}

//uses
//after http request or whatever
Map<dynamic, dynamic> res = await jsonDecode(response.body.toString());
Classname.fromJson(res);