DIAdem Help

Method: Serialize for JsonParser

  • Updated2024-09-12
  • 2 minute(s) read

Method: Serialize for JsonParser

Converts a Dictionary Object or a VBS Array into a JSON object. The items of the dictionary object can contain dictionary objects, VBS arrays, and primitive data types, such as strings, integer, double, and boolean.

sSerialize = Object.Serialize(Value, [PrettifyJson])
ObjectJsonParser
Object with this method
ValueVariant
Specifies a dictionary object or a VBS array.
[PrettifyJson]Boolean
Specifies whether DIAdem formats the JSON string with spaces and word wraps (TRUE) or not (FALSE). If you do not enter a value, DIAdem does not format the JSON string.
sSerializeString

The following example creates a JSON object from a dictionary object containing a dictionary object, an array, a time value, and primitive data types in the items, and displays the contents of the JSON object in the log area:

VBScriptPython

 

Dim oJsonParser, oMySubobject, oMyMainObject, sJsonString
Set oJsonParser = CreateJsonParser()
Set oMySubobject = CreateObject("Scripting.Dictionary")
Set oMyMainObject = CreateObject("Scripting.Dictionary")

Call oMySubobject.Add("intVal", CInt(1))  
Call oMySubobject.Add("doubleVal", CDbl(1.2))
Call oMySubobject.Add("stringVal", "TextA")

Call oMyMainObject.Add("subobject", oMySubobject)
Call oMyMainObject.Add("array", Array("TextB", 5678, True))
Call oMyMainObject.Add("timestamp", oJsonParser.CreateDateTime(Now, True))

sJsonString  = oJsonParser.Serialize(oMyMainObject, True)
Call LogFileWrite(sJsonString)

Log in to get a better experience