1.6 KiB
1.6 KiB
variableFromJSON()
The variableFromJSON() command extracts the value associated with a specific key from a JSON object and stores the result in a target variable. This command is useful for accessing values within a JSON object.
Parameters
- SourceVariable Type: var Description: The variable containing the JSON object from which a value is to be extracted. It can be a variable that stores the JSON object or a direct value representing the JSON object.
- key Type: value Description: The key whose value is to be extracted from the JSON object. It must be a value that represents the key within the JSON object.
- TargetVariable Type: var Description: The variable where the extracted value will be stored. It must be a variable that will receive the value associated with the specified key in the JSON object.
Command Flow
Usage Example
Suppose the JSON object in jsonData is "name": "Alice", "age": 30 and you want to extract the value associated with the key "name".
// Variable definitions
jsonData = {"name": "Alice", "age": 30}
nameValue = ''
// Call the command to extract the value associated with the key "name"
variableFromJSON(jsonData, "name", nameValue)
// Return the extracted value through addResult
addResult(nameValue)
Since the value associated with the key "name" in the JSON object jsonData is "Alice", the variableFromJSON() command will extract "Alice" and store it in the variable nameValue. The nameValue variable will be returned through addResult(nameValue), resulting in the following output:
"Alice"