Jmeter 5.5: extract and store ID value from json response body whose json is in string format

331 Views Asked by At

enter image description hereI want to extract id value from json body whose partner join value is Yes

Response body sample:

{"data":{"data1":"{"recommendedPrograms":{"recommendedProgram":[{"id":"xxxxxxxx","programName":"ProgNme1","programNameLocal":"Prog Test","programDescription":"ProgDesc1","programDescriptionLocal":"Prog level1","partnerJoin":"No","priority":1,"version":"v5"},{"id":"yyyyyyy","programName":"ProgNme2","programNameLocal":"Prog Test2","programDescription":"ProgDesc2","programDescriptionLocal":"Prog level2","partnerJoin":"Yes","priority":1,"version":"v6"},{"id":"zzzzzzzzzz","programName":"ProgNme3","programNameLocal":"Prog Test3","programDescription":"ProgDesc3","programDescriptionLocal":"Prog level3","partnerJoin":"No","priority":1,"version":"v7"}]}"}}

Issue: Since jsonbody is in string format so not able to extract id value directly using json extractor.

Any lead on this will be highly appreciated.

Can anyone help me with beanshell or groovy script to handle id extraction.

Please refer image screenshot for response body sample as back slash is getting removed in the description .

1

There are 1 best solutions below

0
Dmitri T On

What you posted as the text version is not a valid JSON, you won't be able to use either JSON Extractor or Groovy for working with it, you will need to go for i.e. Regular Expression Extractor

I will give you a hint: if you have JSON which is inlined into JSON object you could

  1. Extract data1 attribute value into a JMeter Variable using JSON Extractor

  2. Then you could use another JSON Extractor to extract what you need from data1 JMeter Variable

    enter image description here