AnsweredAssumed Answered

UFL ini where root is JSON array

Question asked by MarkWard on Dec 12, 2018
Latest reply on Dec 13, 2018 by MarkWard

Hi,

 

I'm currently trying to set up an INI file for a REST endpoint whose JSON source is an array rather than a root JSON object. For example, the endpoint will return data like:

As you can see the root of the object is an array and I keep getting errors when trying to parse it using the UFL connector.

 

In order to reference the root as an array I tried using "[]" as the selector for the FOREACH statement in the INI file, but this doesn't seem to work. Not sure what the path is supposed to be in order to select the root as an array. Appreciate any help!

 

I am using UFL Connector version 1.3.0.106

 

The ini file I am using is like:

[FIELD]
FIELD(1).NAME="TagName"
FIELD(2).NAME="Value"
FIELD(2).TYPE="Number"
FIELD(3).NAME="TimeStamp"
FIELD(3).TYPE="DateTime"
FIELD(3).FORMAT="SECONDS_GMT"
FIELD(4).NAME="Variable_String"
FIELD(5).NAME="SoundValue"
FIELD(5).TYPE="Number"
FIELD(6).NAME="TemperatureValue"
FIELD(6).TYPE="Number"
FIELD(7).NAME="HumidityValue"
FIELD(7).TYPE="Number"
FIELD(8).NAME="TimezoneOffset"
FIELD(9).NAME="Device"
FIELD(10).NAME="SensorId"

[MSG]
MSG(1).NAME="Data"

[Data]
Data.FILTER=C1=="*"
TimezoneOffset="08:00:00"
Device="DEVICE"
FOREACH (JsonGetItem(__MESSAGE, "[]")) DO
SensorId = JsonGetValue(__ITEM, "sensor_id")

'Timestamp is in milliseconds, need to convert to seconds
timeStamp = JsonGetValue(__ITEM, "data\ts") / 1000
TimeStamp = timeStamp - TimezoneOffset

SoundValue = JsonGetValue(__ITEM, "data\s")
TagName = "Yitu." & Device & "." & SensorId & ".Sound"
Print(TagName)
Print(SoundValue)
StoreInPI(TagName,"Sound",TimeStamp,SoundValue, ,)

TemperatureValue = JsonGetValue(__ITEM, "data\t")
TagName = "Yitu." & Device & "." & SensorId & ".Temperature"
Print(TagName)
Print(TemperatureValue)
StoreInPI(TagName,"Temperature",TimeStamp,TemperatureValue, ,)

HumidityValue = JsonGetValue(__ITEM, "data\h")
TagName = "Yitu." & Device & "." & SensorId & ".Humidity"
Print(TagName)
Print(HumidityValue)
StoreInPI(TagName,"Humidity",TimeStamp,HumidityValue, ,)
ENDFOR

 

The errors I'm receiving are like:

 

Severity: Error
Timestamp: 12/12/2018 15:47:33.838
Message: [Yitu Test] Error parse line (]): [20, [Line 30] [JsonGetItem] [Error] [Json Parser] [json.exception.parse_error.101] parse error at 1: syntax error - unexpected ']'; expected '[', '{', or a literal exception id: 101 byte position of error: 1.]

 

 

 

EDIT 2018-12-13

I found in the docs that there's an example for iterating through a raw array (link here), however using this ini and returning the test data it provides doesn't work either.

 

Using test data

["VW","BMW","Fiat"]

The stripped .ini is

[MSG]
MSG(1).NAME="Data"

[Data]
Data.FILTER=C1=="*"
FOREACH (JsonGetItem(__MESSAGE, "[]")) DO

Print(__ITEM)
ENDFOR

 

and the error I receive is

[Yitu Test] Error parse line (]): [5, [Line 6] [JsonGetItem] [Error] [Json Parser] [json.exception.parse_error.101] parse error at 1: syntax error - unexpected ']'; expected '[', '{', or a literal exception id: 101 byte position of error: 1.]

 

Really unsure where to go from here even if the test data from the docs doesn't work.

Outcomes