Skip to content
Reference > Methods

toJson(mapListOrLiteral,isCompact)

Definition

String toJson(Object mapListOrLiteral, Boolean isCompact)

Description

Returns a string that contains a nested structure of lists/maps or literals present in the script.

Parameter Definition

Name Type Description
mapListOrLiteral Object A map, list or literal
isCompact Boolean True if the resulting json should contain minimal white space, false otherwise.

Examples

String r1 = toJson("test",true); // r1 == "test"
String r2 = toJson(new List(1, 2, 3, {a=apple, b=berry}),true); // r2 == [1,2,3,{"a":"apple","b":"berry"}]
String r3 = toJson(new List(1, 2, 3, {a=apple, b=berry}),false); // r3 == [
  1,
  2,
  3,
  {
    "a":"apple",
    "b":"berry"
  }
]