Copy (Json function)
Copy the JSON object (Json class)
[Introduced in Model 204 7.6]
This function creates a (shallow) copy of a Json object tree/forest.
Syntax
%outJson = json:Copy
Syntax terms
%json | Json object |
---|---|
Json | Json object, which may be Null |
Usage notes
- The difference between a Copy and a DeepCopy is that a Copy of an array or object Json object only copies the references in the array or object and does not copy the objects referenced by the array or object, but a DeepCopy also copies referenced objects and objects they reference and so on.
Examples
The following makes a copy of an array and the updates the array and an array referenced by the array, printing the values of the source and copy arrays. Note that the update to the nested array is reflected in the copy because the copy simply copied the reference to that array. However, since the outermost array was actually copied, a change to the source array is not reflected in the target:
%json is object json %jsonCopy is object json %json = array(12, 13, 25, array("Moe", "Larry", "Curly")) %jsonCopy = %json:copy %json:add(1.2020569031) %json(4):add("Shemp") printText {~=%json} printText {~=%jsonCopy}
This prints:
%json=[12,13,25,["Moe","Larry","Curly","Shemp"],1.2020569031] %jsonCopy=[12,13,25,["Moe","Larry","Curly","Shemp"]] </xmp>