SET_KEY
Sets an object key to a value. If the key already exists, it will be overwritten. Nested keys can be specified using dot notation.
Categories: Objects
Syntax
SET_KEY(object, path, value)
Examples
Example 1: Adds new keys
Formula
SET_KEY({"name": "Marvin"}, "hair", "brown")
Output
1
{
2
"hair": "brown",
3
"name": "Marvin"
4
}
Example 2: Overwrites keys
Formula
SET_KEY({"name": "Marvin", "age": 30}, "age", 31)
Output
1
{
2
"age": 31,
3
"name": "Marvin"
4
}
Example 3: Works on nested object paths
Formula
SET_KEY({"name": "Marvin", "job": {"company": "Tines", "role": "Software Engineer"}}, "job.role", "Manager")
Output
1
{
2
"job": {
3
"company": "Tines",
4
"role": "Manager"
5
},
6
"name": "Marvin"
7
}
Example 4: Escape dots with backslash
Formula
SET_KEY({".ie": "Ireland"}, "\.co\.uk", "United Kingdom")
Output
1
{
2
".co.uk": "United Kingdom",
3
".ie": "Ireland"
4
}