I had a query regarding fetching a part of json response obtained from 1st request in jmeter to form a new HTTP request.
I wanted to extract 1 block of info json (as it is) with doubles quotes and colon as a part of 2nd HTTP request.
{
"details": [
{
"outBound": [
{
"info": {
"date": "2016-08-11",
"class": "M",
"code": 70,
"pricing": [
{
"totalAmount": 68.8,
"totalTaxAmount": 30.8,
"baseFareAmount": 38.0
}
],
"totalAmount": 68.8,
"totalDuration": 160,
"referenceNumber": 1,
"type": "RP",
"id": 1
},
"segments": [
{
"date": "2016-08-11",
"className": "Standard (W)",
"code": 70,
"totalAmount": 68.8,
"totalDuration": 160,
"referenceNumber": 1,
"type": "RP",
"duration": 160,
"number": "100"
}
]
},
{
"info": {
"date": "2016-08-11",
"class": "M",
"code": 70,
"pricing": [
{
"totalAmount": 78.8,
"totalTaxAmount": 40.8,
"baseFareAmount": 38.0
}
],
"totalAmount": 78.8,
"totalDuration": 160,
"referenceNumber": 2,
"type": "RP",
"id": 2
},
"segments": [
{
"date": "2016-08-11",
"className": "Standard (W)",
"code": 70,
"totalAmount": 78.8,
"totalDuration": 160,
"referenceNumber": 2,
"type": "RP",
"duration": 160,
"number": "200"
},
{
"date": "2016-08-11",
"className": "Standard (W)",
"code": 70,
"totalAmount": 78.8,
"totalDuration": 160,
"referenceNumber": 2,
"type": "RP",
"duration": 160,
"number": "100"
}
]
}
],
"resultCount": {
"count1": 1,
"count2": 1
},
"displayCount": 2
}
]
}
>Expected Output:
{
"info": {
"date": "2016-08-11",
"class": "M",
"code": 70,
"pricing": [
{
"totalAmount": 68.8,
"totalTaxAmount": 30.8,
"baseFareAmount": 38.0
}
],
"totalAmount": 68.8,
"totalDuration": 160,
"referenceNumber": 1,
"type": "RP",
"id": 1
},
"segments": [
{
"date": "2016-08-11",
"className": "Standard (W)",
"code": 70,
"totalAmount": 68.8,
"totalDuration": 160,
"referenceNumber": 1,
"type": "RP",
"duration": 160,
"number": "100",
}
]
}
I tried using JSON PATH POST Processor, but I was getting the extracted data in the form of =
in place of colon and string data without double quotes.
I would recommend using JSR223 PostProcessor instead of this JSON Path one.
groovy
in the "Language" dropdownPut the following code into the JSR223 PostProcessor "Script" area:
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def jsonSlurper = new JsonSlurper();
def response = jsonSlurper.parseText(prev.getResponseDataAsString());
def json = JsonOutput.toJson(response.details[0].outBound[0]);
vars.put("json", json);
${json}
where requiredReferences:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With