Replace$
Replace$
replaces data in a JSON document using a JSON pointer.
Syntax
RETURN_VALUE = JSON_OBJECT.Replace$(EXPRESSION_KEY, EXPRESSION_VALUE)
RETURN_VALUE
is a boolean that indicates whether the operation was successful or not.JSON_OBJECT
is 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.EXPRESSION_KEY
is an expression that corresponds to the key where the value is replaced in the JSON document.EXPRESSION_KEY
uses JSON pointer syntax. You can find more information regarding the syntax of JSON pointers by reading the standard documentation here.EXPRESSION_VALUE
is an expression that corresponds to the value replacing the old value in theEXRESSION_KEY
key.
Examples
# Let's replace a string in a JSON document:
Funprog Replace_Str()
Local Clbfile SRCJSON
SRCJSON = '{"foo": "bar", "bar": "abc"}'
Local Instance OBJ using Object
ParseInstance OBJ with SRCJSON
Local Boolean R1, R2
R1 = OBJ.Replace$("/bar", "quz")
Local Cblfile MYCLB
R2 = OBJ.Get$("", MYCLB)
FreeGroup OBJ
End MYCLB -> Returns {"bar": "quz", "foo": "bar"}
# Let's replace a boolean in a JSON document:
Funprog Replace_Bol()
Local Cblfile SRCJSON
SRCJSON = '{"foo": "bar", "bar": "abc"}'
Local Instance OBJ using Object
ParseInstance OBJ with SRCJSON
Local Boolean R1, R2
R1 = OBJ.Replace$("/bar", true)
Local Cblfile MYCLB
R2 = OBJ.Get$("", MYCLB)
FreeGroup OBJ
End MYCLB -> Returns {"bar": true, "foo": "bar"}
# Let's replace an integer in a JSON document:
Funprog Replace_Int()
Local Cblfile SRCJSON
SRCJSON = '{"foo": "bar", "bar": "abc"}'
Local Instance OBJ using Object
Local Boolean R1, R2
R1 = OBJ.Replace$("/bar", 42)
Local Cblfile MYCLB
R2 = OBJ.Get$("", MYCLB)
FreeGroup OBJ
End MYCLB -> Returns {"bar": 42, "foo": "bar"}
Description
Replace$
replaces the value of a key in a JSON document using the JSON pointer syntax.
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 key does not exist in the JSON document. |
-70 | Invalid argument type. |
See also
Add$
Contains$
Get$
Parse Instance
Remove$
Select$