[HELP] Parse Json with formula inside square brackets

expression
piston

#1

1) Give a description of the problem
I want to parse a json with a lot of data (weather each 5 minutes for the day). So I want to parse the last hour only and its not even sure that the data represent 1 hour (if web request is done close from midnight). I would like to use a formula inside the square bracket that represent the index of the data… Something like:
(count($response.observations.metric.pressureTrend)>12?sum(count($response.observations.metric.pressureTrend),-12):0)

so if the data is enough it will gives the last hour but if not it will give the latest data. The only thing is that when I use this formula like this it doesnt works

$response.observations.metric.pressureTrend[(count($response.observations.metric.pressureTrend)>12?sum(count($response.observations.metric.pressureTrend),-12):0)]

It looks like we could not use formula inside those brackets (I tried to simply use sum(2,2) and the last bracket turned red…

thanks!


#2

Create a variable, set it equal to the formula, then use that variable inside the brackets.


#3

yes, I tried it and it works but I was trying to make it directly in the expression… Is there a way to define a temporary variable inside the expression? Like: test= my formula; $response.observations…[test] ?


#4

No. You’ll need to create and set the variable equal to the formula either in the body of the piston or in the “define” variables section at the top.


#5

ok! thanks!