Get$
Get$ extracts data from a JSON document using a JSON pointer.
Syntax
RETURN_VALUE = JSON_OBJECT.Get$(EXPRESSION, RETURN_OBJECT)
RETURN_VALUEis a boolean that indicates whether the operation was successful or not.JSON_OBJECTis an instance constructed using the ParseInstance instruction applied to a JSON document. This corresponds to the JSON parser used to access and modify the JSON document.EXPRESSIONis an expression that corresponds to the key being searched in the JSON document.EXPRESSIONuses JSON pointer syntax. You can find more information regarding the syntax of JSON pointers by reading the standard documentation here.RETURN_OBJECTis the destination object where the value ofEXPRESSIONis saved.
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. |