Reputation: 35
I want to pass below mentioned json as body raw in Jmeter using groovy. Everything except filter array is working fine. How to pass string array in Jmeter using groovy.
Required Json
{
"Request": {
"request_id": "1121589496445226106",
"request_timestamp": "14122017140114",
"source_node": "CRM",
"dataset": {
"param": [
{
"id": "service_id",
"value": "97694010132"
},
{
"id": "entity_id",
"value": "1"
}
],
"filters": [
"service",
"account",
"profile"
]
}
}
}
Code sample is
import groovy.json.JsonBuilder
def json = new JsonBuilder()
class Tag {String tag; String tagName }
List<Tag> tagsList = new ArrayList<>();
tagsList.add(new Tag(tag:vars.get("serviceid"), tagName:"service_id"))
tagsList.add(new Tag(tag:"1", tagName:"entity_id"))
json {
"Request"
{
request_id "1121589496445226106"
source_node "CRM"
request_timestamp "14122017140114"
"dataset"
{
param tagsList.collect { tag ->
["id" : tag.tagName,
"value": tag.tag]
}
}
}
}
sampler.addNonEncodedArgument("",json.toPrettyString(),"")
sampler.setPostBodyRaw(true)
I want to pass filters array inside json.
Upvotes: 0
Views: 391
Reputation: 35
using below code the required json can be obtained.
import groovy.json.JsonBuilder
def json = new JsonBuilder()
class Tag {String tag; String tagName }
List<Tag> tagsList = new ArrayList<>();
tagsList.add(new Tag(tag:vars.get("serviceid"), tagName:"service_id"))
tagsList.add(new Tag(tag:"1", tagName:"entity_id"))
json {
"Request"
{
request_id "1121589496445226106"
source_node "CRM"
request_timestamp "14122017140114"
"dataset"
{
param tagsList.collect { tag ->
["id" : tag.tagName,
"value": tag.tag]
}
filters'service','account','profile'
}
}
}
sampler.addNonEncodedArgument("",json.toPrettyString(),"")
sampler.setPostBodyRaw(true)
Upvotes: 1