json.path.delete: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{MacroFunction |name=json.path.delete |version=1.5.5 |description= Return a JSON Array or JSON Object with deleted elements. These deletions are specified through the...") |
No edit summary |
||
Line 37: | Line 37: | ||
{"Troll":{"name":"Troll","HP":75,"Attacks":["Claw","Bite"]},"Orc":{"name":"Orc","HP":13,"Attacks":["Sword"]}} | {"Troll":{"name":"Troll","HP":75,"Attacks":["Claw","Bite"]},"Orc":{"name":"Orc","HP":13,"Attacks":["Sword"]}}}} | ||
}} | |||
[[Category:JSON Function]] | [[Category:JSON Function]] |
Revision as of 17:37, 11 September 2019
json.path.delete() Function
• Introduced in version 1.5.5
Return a JSON Array or JSON Object with deleted elements. These deletions are specified through the path parameter. Additional information on how to specify the path is availabe here.
Usage
json.path.delete(json, path)
Parameters
json
- The json element to delete the value from.path
- The path of the values.
Examples
Suppose we have the following nested json:
[h:troll = json.set("{}", "name", "Troll", "HP", 75, "Attacks", json.append("Claw", "Bite"))]
[h:orc = json.set("{}", "name", "Orc", "HP", 13, "Attacks", json.append("Sword", "Punch"))]
[h:monsters = json.set("{}", "Troll", troll, "Orc", orc)]
To delete the "Punch" attack of the Orc, we could write
[r: json.path.delete(monsters, "Orc.Attacks.[1]")]
or, alternatively,
[r: json.path.delete(monsters, "Orc.Attacks[?(@ == 'Punch')]")]
Either statement return the json without the "Punch",
}}