Hi, I have an array of objects, with an array ValTypeCat in ea. object, as follows:
[{"thing_id":"a1", "val":0, "ValTypeCat":[Off, On]},
{"thing_id":"a2", "val":1, "ValTypeCat":[Off, On]}]
Then, with a Change node, I want to use JSONata to show the ValTypeCat array item that corresponds to the val element, ie. val=1 should have On, corresponding to the array entry 1, (vs 0).
To create the payload in the change node, from above incoming msg.payload, and then to show the 1st entry of the ValTypeCat array[0], (thus Off in above example), the following JSONata expression works:
payload.(
{ "thing_id" : $.thing_id,
"val" : $.val,
"ValTypeCat": $.ValTypeCat[0]
}
)
But, this does not work, it brings back the full array.
payload.(
{ "thing_id" : $.thing_id,
"val" : $.val,
"ValTypeCat": $.ValTypeCat['$.val']
}
)
Any ideas of how to do this?