JSON_ADD_ITEM

Use the JSON_ADD_ITEM script function to add an item to a JSON array or object document.

Syntax

JSON_ADD_ITEM (JSON, JSONPath, Value, [,Key,Cast]) or (JSON, JSONPath, Value, [index=-1],[Cast])

Parameters

Return value

None / Error Code in case of error

Runtime errors

The JSON_ADD_ITEM will fail with a runtime error on the following conditions:

Limitations

JSON documents larger than 1MB are not supported

Example

The following script adds a new owner key to the configuration object, and depends the hdd02 entry in the bootSequence array with a new value:

:SET &JSON_DOC# = '[{"host":"192.168.0.10","active":false, "bootSequence":["hdd02"]}]'

:SET &RET# = JSON_ADD_ITEM(&JSON_DOC#, '$[0]', 'superadmin@automic.com','owner')

:SET &RET# = JSON_ADD_ITEM(&JSON_DOC#, '$[0].bootSequence', "ssd01",0)

:PRINT &JSON_DOC#

See also:

seealso

JSON Processing