json.path.put

From RPTools Wiki
Revision as of 16:47, 19 September 2019 by Merudo (talk | contribs) (Created page with "{{MacroFunction |name=json.path.put |version=1.5.5 |description= Add or update the key with the given value at the given path of a nested JSON Object. Additional informati...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

json.path.put() Function

Introduced in version 1.5.5
Add or update the key with the given value at the given path of a nested JSON Object. Additional information on how to specify the path is available here.

Usage

json.path.put(json, path, key, value)

Parameters

Template:paral


|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 add a new "AC" value to the troll, we could write

[r: json.path.put(monsters, "Troll", "AC", "12")]

}}