Pull value from array at variable index in workflow

Hi there!

I’m working on developing a workflow that involves iterating through an array of length N GPIO pin states in a parsed JSON, then based on those pin states, run a loop N times to set the state of the Losant device for each time at which the pin state was sampled.

The parsing is all good, but I’m struggling to figure out how to dynamically fetch the value of an array element at a variable index and set an attribute’s value based on it. I’ve tried the following to no avail:

{{working.jsonParsed.pins.d1.[@index]}}
{{working.jsonParsed.pins.d1.[{{@index}}]}}
{{working.jsonParsed.pins.d1.[working.currTimestamp.index]}}
{{working.jsonParsed.pins.d1.[{{working.currTimestamp.index}}]}}

What am I doing wrong? Is there a better way I’m somehow missing? While I know I could use an array node to pull the element at the index, I do need to be able to perform this same operation on 20+ pins, so I would ideally like to avoid such a messy workaround if a more robust solution is possible.

Thanks for the help!

Hey @Andy_Anderson!

You have to use the lookup helper to dynamically find values (for objects or arrays). Your example would then be something like:

{{lookup working.jsonParsed.pins.d1 @index}}
{{lookup working.jsonParsed.pins.d1 working.currTimestamp.index}}
1 Like