JSON_GET_TYPE

Use the JSON_GET_TYPE script function to get the data type of a JSON element.

Syntax

JSON_GET_TYPE (JSON, JSONPath)

Parameters

Return value: String, one of the following items:

Runtime errors

The function will cause a runtime error under the following circumstances:

Example

The following example checks the type of various elements in a JSON document.

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

!&STRING_TYPE# is 'string'
:SET &STRING_TYPE# = JSON_GET_TYPE( &JSON_DOC#, '$.host')
:P &STRING_TYPE#

!&BOOLEAN_TYPE# is 'boolean'
:SET &BOOLEAN_TYPE# = JSON_GET_TYPE( &JSON_DOC#, '$.active')
:P &BOOLEAN_TYPE#

!&NUM_TYPE# is 'number'
:SET &NUM_TYPE# = JSON_GET_TYPE( &JSON_DOC#, '$.itemNumber')
:P &NUM_TYPE#

!&ARR_TYPE# is 'array'...
:SET &ARR_TYPE# = JSON_GET_TYPE( &JSON_DOC#, '$.bootSequence')
:P &ARR_TYPE#

! ... but &STR_ARR_TYPE# is 'string', because we access the first item of the array
:SET &STR_ARR_TYPE# = JSON_GET_TYPE( &JSON_DOC#, '$.bootSequence[0]')
:P &STR_ARR_TYPE#

Activation report result:

2019-05-13 10:03:24 - U00020408 string
2019-05-13 10:03:24 - U00020408 boolean
2019-05-13 10:03:24 - U00020408 number
2019-05-13 10:03:24 - U00020408 array
2019-05-13 10:03:24 - U00020408 string

See also:

seealso

JSON Processing