I have a Map in flutter
Map<String, dynamic> map = {
'key1': 'Dog',
'key2': 'Chicken',
};
print(map);
Actual Result
{
key1: Dog,
key2: Chicken
}
Expected Result
{
"key1": "Dog",
"key2": "Chicken"
}
You can use any of the following approaches.
Map<String, dynamic> map = {
'key1': 'Dog',
'key2': 'Chicken',
};
print(json.encode(map)); //approach - 1
print(JsonEncoder.withIndent(' ').convert(map)); //approach - 2
Note: don't forget to import dart:convert
.