Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Map<String,String> to a human readable String (in Dart)?

Tags:

dart

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"
}
like image 470
Roger Avatar asked Sep 21 '15 16:09

Roger


1 Answers

use: new JsonEncoder.withIndent(" ").convert(map)

see at dartpad: https://dartpad.dartlang.org/685e0fc43fb4e70c602e

like image 180
Roger Avatar answered Oct 21 '22 20:10

Roger