Skip to main content
The JSONBuilder class simplifies building JSON hierarchies. The result will be a string in correct JSON format, with string values properly escaped. This class is useful for example in combination with the HTTP class to make REST-calls.

Constructors

JSONBuilder()

Initializes a new instance of the JSONBuilder class.

Methods

addBoolean(String,Bool)

Adds a boolean value to the current scope.
Returns: CRMScript.Global.Void
If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty.

addFloat(String)

Adds a float value to the current scope.
Returns: CRMScript.Global.Void
If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty.

addInteger(String,Integer)

Adds an integer value to the current scope.
Returns: CRMScript.Global.Void
If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty.

addString(String,String)

Adds a string value to the current scope.
Returns: CRMScript.Global.Void
If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty. The value does not need to be escaped, it will be escaped by JSONBuilder.

finalize()

Pops all levels out to the root.
Returns: CRMScript.Global.Void
You can call this function instead of multiple popLevel() if you are at then end of your structure.

getString()

Returns the JSON-formatted string that has been built by all push and add methods.
Returns: CRMScript.Global.String - The JSON-formatted string.

popLevel()

Pops a level (closes an array or an object) in the JSONBuilder.
Returns: CRMScript.Global.Void
Look at the root example for this class.

pushArray(String)

Adds an array to the JSONBuilder. Subsequent methods will add members inside the array.
Returns: CRMScript.Global.Void
Normally, an array will be named (because it will be a named variable in the parent scope), except for when the array is the root of the JSON structure.

pushObject(String)

Adds an object to the JSONBuilder. Subsequent methods will add members inside the object.
Returns: CRMScript.Global.Void
Normally, an object will be named (because it will be a named variable in the parent scope), except for when the object is the root of the JSON structure.

setPrettyPrint(Integer)

Sets whether the JSON should be pretty formatted or not.
Returns: CRMScript.Global.Void