Replace$

Replace$ replaces data in a JSON document using a JSON pointer.

Syntax

 RETURN_VALUE = JSON_OBJECT.Replace$(EXPRESSION_KEY, EXPRESSION_VALUE)

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$