I want to fetch a Non-Zero Account Number from Accounts array from below JSON. I am able to Fetch the Accounts in a variable.
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"**Acronym**": "SGML",
"Abbrev": "ISO 8879:1986",
"Accounts": [{"Number":"0","Name":"Zero"},{"Number":"123","Name":"OneTwo"}]
},
"GlossSee": "markup"
}
}
}
}
But I am lost on how to find "Number":"123", and Update the "Name":"OneTwo" to "Name":"OneTwoThree" using Groovy in JMeter. What do I use in this case, what would be efficient, as I will have to run this for several hundred users? Any hints?
[{"Number":"0","Name":"Zero"},{"Number":"123","Name":"OneTwo"}]
Best!
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def builder = new JsonBuilder(response)
response.glossary.GlossDiv.GlossList.GlossEntry.Accounts.findAll { account -> account.Number.equals('123') }.each { account -> account.Name = 'OneTwoThree' }
def data = builder.toPrettyString()
More information:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.