Skip to content
Reference > Methods

toJson(mapListOrLiteral,isCompact)

Definition

String toJson(Object mapListOrLiteral, Boolean isCompact)

Description

Takes a map, list, or literal and returns a string representation of the json that would represent that object.

For a more readable output, the json can be rendered with additional whitespace,or can be stored in condensed form.

Parameter Definition

Name Type Description
mapListOrLiteral Object A map, list, or literal
isCompact Boolean "true" if the resulting json should contain minimal whitespace, "false" otherwise (for better readability).

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"
  }
]