Sylvia Lobo
Sylvia Lobo

Reputation: 407

How to parse JSON data?

I need to find all id values where available":true:

Formated for better readability:

{
   "KEN":[
      {
         "name":"Mombasa",
         "id":"MBA",
         "available":false,
         "group":[

         ],
         "children":[

         ],
         "countryName":"Kenya",
         "countryCode":"KEN",
         "synonym":""
      }
   ],
   ...
}

Actual JSON string

{"KEN":[{"name":"Mombasa","id":"MBA","available":false,"group":[],"children":[],"countryName":"Kenya","countryCode":"KEN","synonym":""}],...

I have tried to parse it with the following regular expression

\{"name":".+?","id":"(.+?)","available":true,.+?,"synonym":""\}

but its not working.

I am using Regular Jmeter.

Upvotes: 1

Views: 121

Answers (1)

Dmitri T
Dmitri T

Reputation: 168092

Use JSONPath Extractor available via JMeter Plugins

Relevant JSONPath query will look somehow like

.KEN.[?(@.available=='false')].id

See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for instructions on plugin setup and some form of JSONPath language reference.

Upvotes: 1

Related Questions