How To Extract JSon Values From NodeRed JSon Object
In this Post I will Step Through on How to Extract JSON Value from Node Red JSon Object.
We will Use the below JSon object as an Example ,
In this JSon Object we will Extract the value “truck ” and the “political” value .
Before we deep dive into Setting up the node , Let go through on how to Read the JSON Object
“volume” is the second key Value of the Json Object ,and “volume” is package as an Array . The Array length of the “volume” Array is equal to 6 . The First Array of “volume ” which is also an Array has an Array Length of 6.
To get the “truck” Value. We understand that “truck” reside inside the the First index of the Array , and the Array reside in index 0 of the “volume” Array.
To get the “political” Value . We understand “political is the third key of the JSon Object
Nodes that you will Need
- Inject Node
- JSon convert Node
- function Node
- 2 Debug Node to output “truck ” and “political” Value
Build the Sample Node
Step 1
Drag out an inject Node and Configure as below, Click the ” … ” and Paste the Sample JSON into the text Area
Step 2
Drag out the JSon Objects Node and Configure as below
Step 3
Drag Out the Function Node Click the Setup Tab and Configure as Below . When Done Click the On Message Tab and paste the Code below into the Text Area.
Step 4
Drag Out 2 Debug node and Provide a logical name . In my case i name it ” Extract Truck Word ” and ” Political Value ”
Step 5
Joint all the Nodes and Click Deploy . Observe the Results
Results
Check out Multiple Output From Node Red
Leave a Reply