Sets a key of an object to a specified value, creating a new key if it doesn’t exist already.
Input Fields
- object: the object you are starting with
- path: can be a single top-level key name (e.g. “customer”), a dot-delimited path (e.g. “customer.id” where “id” is a key inside a sub-object or “items.5” where 5 is an element inside a list), or you can change the type of path to accept a list of text each containing a single key name for the path
- value: the new value for the key. Be sure to set the type of value to match the desired type (e.g. text or number) for the key.
Output Fields
- output: the new object containing the updated value in the specified path
Examples
If object is {"foo":"1"}
, path is foo
, and value is 2
, then output is {"foo":"2"}
.
If object is {"foo":"1"}
, path is bar
, and value is 2
, then output is {"foo":"1","bar":"2"}
.
If object is {"foo":"1"}
, path is bar.baz
, and value is 2
, then output is {"foo":"1","bar":{"baz":"2"}}
.
If object is {"foo":["0","1","2"]}
, path is foo.1
, and value is 9
, then output is {"foo":["0","9","2"]}
.
If object is {"foo":{"bar":"1"}}
, path is foo.bar
and value is 2
, then output is {"foo":{"bar":"2"}}
.
Alternatively, you can set the type of path to be a list of text and then pass in “foo” and “bar” as the list items to get the same result.
When using a list of text, dots are assumed to be part of the desired key name so using foo.bar
as the input if path is set to a list would result in the output {"foo":{"bar":1},"foo.bar":2}