DeepCopy (Json function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
No edit summary
 
Line 1: Line 1:
{{Template:Json:DeepCopy subtitle}}
{{Template:Json:DeepCopy subtitle}}
 
This function creates a deep copy of a Json object tree/forest. A deep copy is one where not only are the contents of the object copied but all objects referenced by the objects and all objects referenced by those and so on.  
This page is [[under construction]].
==Syntax==
==Syntax==
{{Template:Json:DeepCopy syntax}}
{{Template:Json:DeepCopy syntax}}
Line 11: Line 10:
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<li>The difference between a DeepCopy and a [[Copy (Json function)|Copy]] 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.</li>
<li>The copy of a null object is, of course, null.</li>
<li>When a Json object is passed between a daemon and master or vice versa, the Json object is deep copied.
</ul>
==Examples==
==Examples==
The following makes a deep 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 neither the update to outer nor the nested array are reflected in the copy because the deep copy made copies of all objects in the tree so the %jsonCopy tree is totally independent of the %json tree. Contrast this with the nearly identical example for [[Copy_(Json_function)#Examples|Copy]]:
<p class="code">%json      is object json
%jsonCopy  is object json
%json = array(12, 13, 25, array("Moe", "Larry", "Curly"))
%jsonCopy = %json:deepCopy
%json:add(1.2020569031)
%json(4):add("Shemp")
printText {~=%json}
printText {~=%jsonCopy}
</p>
This prints:
<p class="code">%json=[12,13,25,["Moe","Larry","Curly","Shemp"],1.2020569031]
%jsonCopy=[12,13,25,["Moe","Larry","Curly"]]
</p>
==See also==
==See also==
{{Template:Json:DeepCopy footer}}
{{Template:Json:DeepCopy footer}}

Latest revision as of 22:04, 17 February 2015

Copy the JSON object (Json class)

[Introduced in Model 204 7.6]

This function creates a deep copy of a Json object tree/forest. A deep copy is one where not only are the contents of the object copied but all objects referenced by the objects and all objects referenced by those and so on.

Syntax

%outJson = json:DeepCopy

Syntax terms

%jsonJson object
Json Json object, which may be Null

Usage notes

  • The difference between a DeepCopy and a Copy 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.
  • The copy of a null object is, of course, null.
  • When a Json object is passed between a daemon and master or vice versa, the Json object is deep copied.

Examples

The following makes a deep 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 neither the update to outer nor the nested array are reflected in the copy because the deep copy made copies of all objects in the tree so the %jsonCopy tree is totally independent of the %json tree. Contrast this with the nearly identical example for Copy:

%json is object json %jsonCopy is object json %json = array(12, 13, 25, array("Moe", "Larry", "Curly")) %jsonCopy = %json:deepCopy %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"]]

See also