0
votes

I have created a json block file which looks like this, I like to add a new element i.e

{
  "Id": 0,
  "cc": "123"
}

I need to add a new element

"xyz": ${abc}

the resulting to look like

{
  "Id": 0,
  "cc": "123",
   "xyz": ${abc}
}

I have retrieved the file

String json1 = vars.get("basePath")+"Jmeter/Results/json1";
json1= new groovy.json.JsonSlurper().parse(json1);

How do I add

"xyz": ${abc},  

to json1 ?

1
Possible duplicate Refer to this question stackoverflow.com/questions/32988456/… - Rohit

1 Answers

0
votes

Use the following code:

String json1 = vars.get("basePath")+"Jmeter/Results/json1";
def parsedJson = new groovy.json.JsonSlurper().parse(json1);
parsedJson.put('xyz',vars.get('abc'))
def newJson = new groovy.json.JsonBuilder(parsedJson).toPrettyString()

More information: