Page tree
Skip to end of metadata
Go to start of metadata

JSON format manipulation functions

JSON format manipulation functions allows to create, read, write and delete JSON objects. Function names are created by the prefix %JSON_.

When adding invalid value (e.g. %JSON_ObjectSetValue), value in JSON is stored as null. When reading null value from JSON (e.g. %JSON_ObjectGetValue), value is interpreted as invalid value.

Every handle to JSON object or array must be released by calling %JSON_FreeObjectHandle or %JSON_FreeArrayHandle.

Handle remain valid also after deleting of child object or array (e.g. %JSON_ArrayRemoveItem) pointed to by the handle. Similarly when removed parent object or array, handle pointed to child remains valid.

Example:

INT _obj
INT _clientInfo
TEXT _d2version
 
_obj := %JSON_ObjectFromString(ModuleInfo)
_clientInfo := %JSON_ObjectGetObject(_obj, "client_data")
 
%JSON_FreeObjectHandle(_obj) ; release handle to _obj, _clientInfo is still valid handle
 
_d2version := %JSON_ObjectGetValue(_clientInfo, "d2000_version")
 
LOG "D2000 version", _d2version PRIORITY _LOG_PRTY_INFO
 
%JSON_FreeObjectHandle(_clientInfo) ; finally release _clientInfo handle

There is created JSON object from ModuleInfo variable, then we get value from object and this value is written into monitoring database.

%JSON file manipulation functions:


Related pages:

Write a comment…