Data Conversion Using a JSON Query Node

This guide assumes familiarity with:

In this guide, you'll learn how to get specific values in a usable format from raw JSON data using the JSON Query Node.

Example: "Increase the volume of the speaker by 30%."

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.

{
"results": [
{
"id": "6a2e9434-5b19-47s0-92a8-685de69106a3",
"status": "ACCEPTED"
}
]
}

Extracting Information With a JSON Query Node

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.

  1. Connect the Start Node's main port to the Command Node's trigger port, and the Start Node's brightess value port to the Command Node's Level port.

  2. Add a JSON Query Node to the action flow. The JSON Query Node parses and extracts values or objects from the JSON response, which allows you to convert the data into a usable format. JSON Query node The node has two input parameters and two output parameters. Parameters in JSON query node

    Input Parameters:

    • Node trigger: It's a trigger point of the node which executes it.
    • JSON Object: Specifies the input JSON object.

    Output Parameters:

    • Main: It's an output trigger port of the node, which specifies the next course of action or node in the action flow.
    • Node Value: Specifies the output value of the node.
  3. Click the JSON Query Node to open the node configuration menu on the right. JSON Query Node Configuration Menu Opens on Right

  4. Configure the node by entering a pointer value and selecting a dataType from the drop-down menu. This example uses the pointer value "/results/0/status" and the dataType "String." This pointer value selects the status property of the "results" and parses the status property from the response JSON. For more information on the pointer, see the note below. JSON Query Node Configuration Menu

    • Pointer: The JSON Pointer configuration can select a value by the JSON Pointer specification.
    • Data type: The node's output value type can be set to Boolean, Integer, Number, Object, Duration, ColorMap, String, or Vocab.
  5. Connect the 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.

  6. Add an Equal Comparison Node and configure it to use the equalTo operator.

  7. Connect the 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.

  8. Add a Constant Node and configure it to the String value of "ACCEPTED."

  9. Connect the Constant Node's value port to the Equal Comparison Node's rightValue port.

  10. Add a Response: Success Node and a Response: Execution Failed Node to the action flow.

  11. Connect the 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:

Final Action Flow

Note

The pointer defines the string syntax for identifying a specific value in a JSON object. Here's an example:

Pointer usage table with 4 columns: Output result type, Input JSON (example), Pointer, and Output. There are 4 rows with example data.

Testing Your Action Flow

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:

Action Flow for JSON Query Node

As shown in the example graph, the user's utterance value is 30. The user utterance "Increase the volume of the speaker by 30 percent." 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": "17c467a6-6660-4488-a192-12c2a59d5c28",
"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.