Links

setItem

To update or add a key-value pair in a given JSON object
With this function, you can update an already existing JSON object and add more data to it.
If your JSON object is stored in a variable, it will be modified even if the return value is not stored in the variable again.

Syntax

setItem(JSON, string, any)

Return

JSON

Examples

setItem(object, key, newValue) Updates a key-value pair in a given JSON object.
1
let data := {
2
lastName: "Rogers",
3
firstName: "Steve"
4
};
5
setItem(data, "firstName", "Brian")
Result: The object data is changed: The value assigned to the key firstName is overwritten with the value Brian.
setItem(object, newKey, newValue) Adds a key-value pair to a given JSON object.
1
let data := {
2
lastName: "Rogers",
3
firstName: "Steve"
4
};
5
setItem(data, "age", 112)
Result: The object data is supplemented by the key-value pair age: 112.

See also

removeItem, which removes a key-value pair from a given JSON object.
Last modified 5mo ago