GetAryData
Overview
What Is GetAryData?
GetAryData is a SimpleJSON library function for extracting a specified element from a JSON array. JSON arrays can hold various data such as strings, numbers, Objects and arrays, and GetAryData gets the data at the position specified by DataIndex as-is.
JSON data received from Web APIs and JSON messages received from AWS IoT Core and the like sometimes contain multiple data items stored as an array. This function is used when handling such data on a PLC.
When it is used
GetAryData is used for purposes such as the following.
- Parsing JSON arrays obtained from Web APIs
- Processing JSON data received from AWS IoT Core on the PLC
- Extracting Objects in a JSON array
- Getting arrays inside an array in order
- Receiving equipment information and sensor data in array form
Symbols
GetAryData
Extracting elements from a JSON array

- In
- BYTE[*]
- String starting with [
- DataIndex
- UINT
- Element number
- out
- BYTE[65535]
- Element value
About DataIndex
JSON arrays are numbered from 0.
| DataIndex | Data obtained |
|---|---|
| 0 | First element |
| 1 | Second element |
| 2 | Third element |
Specifying a number that does not exist gives empty data.
Getting an Object
Even if an element of the JSON array is an Object, it can be obtained. The obtained data is a JSON string, so you can then use the Get function or similar to get data in the Object.
Getting an array inside an array
If an element of the JSON array is itself an array, it can also be obtained. By running GetAryData again on the obtained JSON array, nested arrays can be extracted in order.
Usage notes
- The input data must be a JSON array starting with "[".
- It cannot be used on JSON Objects.
- Specifying a DataIndex that does not exist gives empty data.
- Obtained Objects can be parsed with the Get function or similar.
Difference from the Get function
| Function | Use |
|---|---|
| Get | Gets from a JSON Object by key name |
| GetAryData | Gets from a JSON array by element number |
Execution example
In data (JSON)
Output when DataIndex=0 is specified
out
Output when DataIndex=1 is specified
out
FAQ
Can Objects inside an array be obtained?
Yes. The entire Object is returned as a JSON string.
What if DataIndex is out of range?
The result is empty data.
Can arrays inside an array be obtained?
Yes. Use GetAryData again after obtaining it.
