Get$

Get$ extracts data from a JSON document using a JSON pointer.

Syntax

 RETURN_VALUE = JSON_OBJECT.Get$(EXPRESSION, RETURN_OBJECT)

Note: If EXPRESSION is an empty string, the entire JSON document is assigned to RETURN_OBJECT as a string/CLOB.

Examples

# Let's get a string from a JSON document:
Funprog Get_Str()
	 Local Clbfile SRCJSON
	 SRCJSON = '{"foo": "bar", "bar": "abc"}'
        Local Instance OBJ using Object
        ParseInstance OBJ with SRCJSON
        Local Char MYSTR(56)
        Local Boolean R
        R = OBJ.Get$("/bar", MYSTR)
        FreeGroup OBJ
End MYSTR -> Returns "abc"
# Let's get a boolean from a JSON document:
Funprog Get_Bol()
	 Local Clbfile SRCJSON
	 SRCJSON = '{"foo": true, "bar": "abc"}'
        Local Instance OBJ using Object
        ParseInstance OBJ with SRCJSON
        Local Char MYBOOL
        Local Boolean R
        R = OBJ.Get$("/foo", MYBOL)
        FreeGroup OBJ
End MyBol -> Returns 1
# Let's get a number from a JSON document:
Funprog Get_Int()
	 Local Cblfile SRCJSON
	 SRCJSON = '{"foo": 42, "bar":"abc"}'
        Local Instance OBJ using Object
        ParseInstance OBJ with SRCJSON
        Local Boolean MYINT
        Local Boolean R
        R = OBJ.GET$("/foo", MYINT)
        FreeGroup OBJ
End MYINT -> Returns 42

Description

Get$ assigns a JSON pointer to an object with the corresponding value of the expression searched as a key in the JSON document.

The result of this function has the boolean type.

Return values

Value Explanation
0 Operation succeeded.
-6 The name of the variable does not exist in the JSON document.
-26 Invalid JSON document or the parsing of the searched key has failed.
-70 Invalid argument type.

See also

Add$
Contains$
Parse Instance
Remove$
Replace$
Select$