1.5 KiB
1.5 KiB
AddVariableToJSON()
The AddVariableToJSON() command adds a new key and its corresponding value to a JSON object and stores the result in a target variable. This command is useful for updating a JSON object with new key-value pairs.
Parameters
- Key Type: variable Description: The key to be added to the JSON object. It must be a variable that stores the key to be added.
- Value Type: variable Description: The value associated with the key to be added to the JSON object. It must be a variable that stores the corresponding value.
- TargetVariable Type: variable Description: The variable where the updated JSON object will be stored. It must be a variable that will receive the JSON object with the new key and its added value.
Command Flow
Usage Example
Suppose the initial JSON object in jsonData is "name": "Alice", "age": 30, and you want to add a new key "email" with the value "alice@example.com".
// Variable definitions
jsonData = {"name": "Alice", "age": 30}
newKey = "email"
newValue = "alice@example.com"
// Call the command to add the new key and value to the JSON object
AddVariableToJSON(newKey, newValue, jsonData)
// Return the updated JSON object through addResult
addResult(jsonData)
This updated JSON object will be stored in the variable jsonData and will be returned through addResult(jsonData), resulting in the following output:
{
"name": "Alice",
"age": 30,
"email": "alice@example.com"
}