Unanswered question

How to work with JSON objects within conditions

How would I use a JSON object within an if…then…else condition?

In my case I'm iterating across a JSON object, which has four object elements. The loop runs four times as expected. Within the loop I'm trying to evaluate whether or not the value of the key "isMine" is true or not. I tried this as follows:

Operand1: ${contracts_json}[${contractLoop_counter}].isMine
Condition: Equals
Operand2: true

Unfortunately Operand1 always contains the whole ${contracts_json} object and not just one of the four elements. Therefore the condition never evaluates to true. How should I evaluate a specific element? I also tried setting Condition1 to ${contracts_${contractLoop_counter}}.isMine, but this does not work either.

Any suggestions?

Kai K.
Kai K.

Kai K.

Level
0
39 / 100
points

Answers

Fousseyni B.
Fousseyni B.

Fousseyni B.

Level
2
1014 / 2000
points

Hello Kali,

Why not use a simple extractor ?
If the extractor variable does not contain what you are looking for, you will do a further extraction using a javascript action to capture what you are looking for.

Best Regards,
Fousseyni B.

Kai K.
Kai K.

Kai K.

Level
0
39 / 100
points

Hi Fousseyni,
thanks for your reply. I could also extract contractId and contractIsMine from the JSON object to two separate variables. This for example would give my foo=[21,24,54,53] and bar=[false, true, true, false]. I could then evaluate bar, and only load foo[1] and foo[2]. However this is not the best solution in my opinion.