This guide assumes familiarity with the following information:
Command
node (Sending a Device Command)Constant
node (Creating a Bixby Response Using a Device Status)Equal Comparison
node (Concatenating Actions)Response
node (Creating a Bixby Response Using a Device Status)In this guide, you'll learn how to get specific values in a usable format from raw JSON data using the JSON Query
node. The device used in this guide is a SmartThings-enabled speaker, with the example utterance "Increase the volume of the speaker by 50".
For this voice command, you must get the result of a command and give the user the information. Sometimes the output of nodes (responses) are in JSON format. To extract information from these responses, you can use the JSON Query
node.
Here is an example JSON response:
{
"results": [
{
"id": "6a2e9434-5b19-47s0-92a8-685de69106a3",
"status": "ACCEPTED"
}
]
}
To start extracting information, you first need to build your action flow with a Start
node and a Command
node, like in the Sending a Device Command guide.
Start
node's main port to the Command
node's trigger port, and the Start
node's volumeLevel
value port to the Command
node's Level port.
JSON Query
node to open the Node Configuration menu on the right.
/results/0/status
and the data type String
. This pointer value selects the status
property of the results
and parses the status
property from the response JSON. The JSON Pointer configuration selects a value with the JSON Pointer specification.
Command
node's success port to the JSON Query
node's trigger port, and its value port to the JSON Query
node's input port.Equal Comparison
node and configure it to use the equalTo
operator.JSON Query
node's main port to the Equal Comparison
node's trigger port, and its value port to the Equal Comparison
node's leftValue
port.Constant
node and configure it to the String
value of "ACCEPTED."Constant
node's value port to the Equal Comparison
node's rightValue
port.Response: Success
node and a Response: Execution Failed
node to the action flow.Equal Comparison
node's true port to the Response: Success
node's trigger port, and its false port to the Response: Execution Failed
node's trigger port.The following image shows the finished action flow:
The pointer defines the string syntax for identifying a specific value in a JSON object. Here's an example:
Output Result Type | Input JSON (Example) | Pointer | Output |
---|---|---|---|
string or mixed | {
"id": "<uuid>",
"status": "ACCEPTED"
} | /status/ | "ACCEPTED" |
JSON object | {
"results": {
"id": "<uuid>",
"status": "ACCEPTED"
}
} | /results/ | {
"id": "<uuid>",
"status": "ACCEPTED"
} |
array | {
"results": [ {
"id": "<uuid>",
"status": "ACCEPTED"
} ]
} | /results/ | [ {
"id": "<uuid>",
"status": "ACCEPTED"
} ] |
array object | {
"results": [ {
"id": "<uuid>",
"status": "ACCEPTED"
} ]
} | /results/0/status/ | "ACCEPTED" |
To test the action flow, click the Try It button at the top right of the editor window. The flow editor should look like this:
As shown in the example graph, the user's utterance value is 50. The user utterance "Increase the volume of the speaker by 50" executes the SmartThings Capabilities audioVolume
command. For more information, see Sending A Device Command With an Argument.
For the audioVolume
POST command, the server responds with JSON:
{
"results": [
{
"id": "6d0dc5d1-c76d-48e6-bd64-0e834dd52778",
"status": "ACCEPTED"
}
]
}
The JSON Query
node selects the status
property of the results
and parses the status
property from the response JSON. Bixby then compares the status
property output by the JSON Query
node to the string "ACCEPTED" in the Constant
node. The Equal Comparison
node determines that these values are equal and triggers the "SUCCESS" response.
The Node Recommendation feature enables you to get recommendations for next possible nodes, and can make it easier to create a graph.