Is it possible to pretty format a json string: Map m = Map(data); printLine(m.toJson());
Outputs: { "First": "Martin", "Last": "Andersen"}
I would like to have it like this:
All Replies (4)
Not by default, but you can use the code shared by Sverre here: Simple JSON formatter in CRMScript
Hi Martin, this should work:
#setLanguageLevel 4;
Map data;
data.insert("First", "Martin");
data.insert("Last", "Andersen");
printLine(parseJSON2(data.toJson()).toJSON(2));
Very nice, two options. One is a custom function which can be changed to suit your needs. The other is inbuilt and most likely much faster, but it needs to convert to XML and as such duplicate your data and use a lot of lists to make the xml manageable internally, and it will use a lot of memory. But if you have memory left, this will be faster and you don’t need to define a method.
Thank you both.