0

I want to extract JSON block where it satisfies multiple conditions. For example, extract a block which has variables with two or more desired value. Please see below given example.

[
  {
   id:"1",
   name:"ABC - Project 1",
   appName:"XYZ",
   state:"New",
   appType:"owner",
   date:"May 12"
  },

  {
   id:"2",
   name:"DEF - Project 2",
   appName:"UVW",
   state:"In Progress",
   appType:"manager",
   date:"May 13"
  },

  {
   id:"3",
   name:"GHI - Project 3",
   appName:"RST",
   state:"In Progress",
   appType:"owner",
   date:"May 12"
  },

  {
   id:"4",
   name:"JKL - Project 4",
   appName:"OPQ",
   state:"Expired",
   appType:"entity owner",
   date:"July 13"
  }
]

From the above JSON, I want to extract the JSON block where state:"In Progress" or state:"New", either of these states and it should of appType:"Owner" along with name:... Project 1; i.e. the following blocks as output:

  {
   id:"1",
   name:"ABC - Project 1",
   appName:"XYZ",
   state:"New",
   appType:"owner",
   date:"May 12"
  }

Which JSON Path expressions whould I use to extract:

$.[?((@.state == "In Progress" || @.state == "New") && @.appType== "owner" && <some regex expression>)]

But it doesn't extract any result. Is there any way to use multiple conditions for "OR/||" and "AND/&&" condition to extract that particular block. Please help!

Thanks, Sid

1 Answer 1

2

Your expression works fine for me:

enter image description here

So you might want to double check:

  • jmeter.log file for any suspicious entries like Error processing JSON content in JSON Extractor
  • the values of the JMeter Variables as depending on your JSON Extractor configuration the values may be written into variables with indices, i.e. you expect FOO but you're getting FOO_1 and FOO_2, it can be done using Debug Sampler and View Results Tree listener combination
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, It worked for me now. But the question now is if I want to use regex to pick a name from the JSON block, for eg., if name: Project 1 - Hello World and I want to identify using "Hello World", can I do it using JSON path expression? $.[?((@.state == "In Progress" || @.state == "New") && @.appType== "owner" && <some regex function>)]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.