Developer Documentation Library > Scripting > UNICOM Intelligence Function Library > Miscellaneous functions > JsonSerialize
 
JsonSerialize
Turn a simple type, Properties object, or dynamic object into a JSON string.
Syntax
JsonSerialize(Value[, Indent[, SingleLineArrays[, CategoricalsAsText]]]) As String
Parameters
Value
Type: Variant
The value to be serialized into JSON. Simple types such as integer or text values and objects can be serialized into JSON. Objects returned by CreateObject() used without a parameter, or Properties collections (mrProperties.Properties) can be serialized. Attempts to serialize other object types result in an error.
Indent
Type: Long
Optional. Formatting option that specifies the number of spaces when the JSON is formatted over multiple lines. If the value is negative or omitted, all JSON is formatted on a single line.
SingleLineArrays
Type: Bool
Optional. Specifies whether arrays should be formatted over multiple lines. True can be used to format the array elements on a single line.
If multi-line formatting is enabled (that is, Indent is zero or greater than zero), the default is to format arrays over multiple lines.
If multi-line formatting is not enabled (that is, Indent is omitted or less than zero), this value is ignored.
CategoricalsAsText
Type: Bool
Optional. Specifies formatting for categorical values. By default categorical values are formatted as an array, for example [32,33].
If CategoricalsAsText is True, the categorical value is formatted as a string, for example: {32,33}.
If a metadata document is available, categorical names are used, for example: {north,south}.
(return)
Type: String
Returns the variant in JSON format in a string.
Example
This example uses CreateObject() to create a dynamic object, and shows how to use the . (dot) notation to specify property names.
Dim StyleObject
Dim JSON
Dim FSO
Dim TextStream
Dim Values[2]

Set StyleObject = CreateObject()
StyleObject.TemplateName = "PeopleWorking"
StyleObject.Color = "Red"
StyleObject.Logo = "PeopleWorkingRed.png"
StyleObject.Categories = {23}
Values[0] = "Hello"
Values[1] = 42.01
StyleObject.Values = Values
StyleObject.Font = CreateObject()
StyleObject.Font.Face = "Arial"
StyleObject.Font.Size = 12
StyleObject.Font.Italics = True

JSON = JsonSerialize(StyleObject, 4, True)
Debug.Log(JSON)
Example
This is an example of serializing a categorical value.
Routing(Web)
Location.Ask()
TextQ.Response.Value = JsonSerialize(Location.Response.Value, -1, False, True)
TextQ.Show()
End Routing
See also
JsonDeserialize
CreateObject
Miscellaneous functions