util::json::object::set_by_path (public)
util::json::object::set_by_path -object object -path path -value value
Defined in packages/acs-tcl/tcl/json-procs.tcl
This is an odd utility that mimics some odd code in the Ilias SCORM module, included here because it might be of more general use. Essentially we walk down an object tree structure using the "path" parameter. If we encounter a leaf on the way, we replace it with a new object node and continue. The last element of the path is interpreted as a leaf of the tree and is set to "value". Example: util::json::gen [util::json::object::set_by_path -object "" -path {a b c} -value 3] Result: {"a":{"b":{"c":3}}} Example: util::json::gen [util::json::object::set_by_path -object [util::json::object::create [list a [util::json::object::create [list d null]]]] -path {a b c} -value 3] Result: {"a":{"b":{"c":3},"d":null}} "a" is the top level object with two subnodes "b" and "d", with "b" having a subnode "c" of value 3, and "d" being a leaf of "a" with value "null".
- Switches:
- -object (required)
- The object to add subnodes to.
- -path (required)
- The path through the tree with the last value being the name of a new or existing leaf.
- -value (required)
- The value to set the final leaf to.
- Returns:
- A new object with the new tree structure interwoven into it.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.