JSON Object Classes & Variable Types
JSON Object Classes
The advantage of encoding data into a relatively plain string text format of characters such as JSON, is that it can be passed easily between a web browser and web server, or can be read from or saved to a text file on disk, making it an ideal data‑interchange language.
As detailed below, specific characters such as square brackets [ and ], and curly braces { and }, are used to mark the structural aspects within the string.
The fundamental data element in JSON is a name/value pair (or key/value pair or property).
A JSON structure is built from JSON objects. An object is an unordered set of name/value pairs, starting with a left curly brace { and ending with a right curly brace }.
The JSON name (key) and value are separated by a colon : and each set of pairs is separated by a comma.
The name of the JSON item is always in the left side of the colon.
A JSON Array is an ordered collection of values, beginning with a left square bracket [, and ending with a right square bracket ].
Values are separated by commas.
Each Object or Array can contain a combination of Objects, Arrays, name/value pairs, and/or simple data values (e.g. a string in double quotes such as AbC, a number, true or false or null, an object or an array), to any required depth of nesting.
Further details can be found at http://www.json.org and elsewhere.
There are 7 pre-defined classes available to deal with JSON entities:
TJSONValue – The base class of all the JSON classes used to store parsed JSON data. The rest of the JSON related classes are inherited from TJSONValue. Any of the JSON entities can be treated as TJSONValue, for example, can be serialized into a string.
TJSONObject – Represents a JSON object. It holds a set of paired keys (strings) and values (TJSONValue), and provides an easy-to-use interface to access and modify them. Also referred to as name/value pairs or properties.
TJSONArray – Represents a JSON array. It keeps an array of enclosed TJSONValue values, and can include unnamed objects.
TJSONString, TJSONNumber, TJSONBool, TJSONNull – Represents string, number, boolean and null values respectively.

Remember: JSON objects and arrays are always passed by reference as regular objects in Statelake script. When you modify an object or array by using a variable (reference), you actually modify the original object or array that the variable refers to.
JSON Variable Types
Every JSON value can be tested for a specific type, by either using the is operator, or one of the following functions:
IsString
IsInt
IsInt64
IsNumber
IsBoolean
IsObject
IsArray
Sample code -
if
object
[
'str'
].IsString
then
LogInfo(
'str field is a string'
);
if
object
[
'str'
]
is
TJSONString
then
LogInfo(
'str field is a string'
);
if
object
['number’].IsNumber
then
LogInfo(‘number field
is
a number’);
if
object
['number]
is
TJSONNumber
then
LogInfo(‘number field
is
a number’);
if
jsonValue
.
IsObject
then
LogInfo(
'jsonValue is an object'
);
if
jsonValue
is
TJSONObject
then
LogInfo(
'jsonValue is an object'
);