Reputation: 161
I'm trying to convert a Map to a human readable string.
So let's say I have this Map:
Map<String, String> map = { "foo": "lorem", "bar": "ipsum" };
I want to convert it too the following string, including the indents:
{
"foo": "lorem",
"bar": "ipsum"
}
Upvotes: 5
Views: 9480
Reputation: 161
use: new JsonEncoder.withIndent(" ").convert(map)
From the new dartpad linq with the same url fragment 685e0fc43fb4e70c602e
import "dart:convert";
main() {
var map = { "foo": "lorem", "bar": "ipsum" };
print(new JsonEncoder.withIndent(" ").convert(map));
}
see at dartpad: https://dartpad.dartlang.org/685e0fc43fb4e70c602e (old link is dead)
Upvotes: 11
Reputation: 1
Using this code you can convert your map to a JSON string.
import "dart:convert";
var mapInJsonString = json.encode(map);
Upvotes: 0