Reputation: 89
In Jmeter , I am trying to extract value from a json. Here is the json response i received :
{
Definition: {
key: 1124,
Id: 1743,
srcID: "3427",
pcKey: -1,
userName: "abraizada",
cName: "JMeter2016-11-27-1480283993838",
Type: "SUBJECT",
cohortTool: "Web app",
cCount: 74,
extractionStatus: "Completed",
dateCreated: "2017-05-09T18:35:35Z"
},
datasource: {
id: 2,
name: "Claims-OMOP",
subjectCount: 116352
},
project: {
id: 747,
name: "Jmeter Project"
}
},
{
cohortDefinition: {
key: 1123,
Id: 1742,
srcID: "3447",
pcKey: -1,
userName: "IE_USER",
cName: "JMeter2016-11-15-1479204865900",
Type: "SUBJECT",
cohortTool: "Web app",
cCount: 74,
extractionStatus: "",
dateCreated: "2017-05-09T18:35:35Z"
},
datasource: {
id: 2,
name: "External",
sCount: 116352
},
project: {
id: 747,
name: "Jmeter Project"
}
},
From above response , I would like to extract value 'key' if srcID=3447. I tried doing this $..cohortKey[?(@.srcCohortId = 3447)].cohortKey
But not getting result. Could anyone help me in extracting "key" value based on condition.
Upvotes: 1
Views: 5103
Reputation: 216
You can use JSON Extractor to do this with the JSON Path expressions like below:
$..[?(@.srcID==3447)].key
where:
..
- is recursive descent, it help to find everywhere in the json data[]
- an array, means the filter will apply and find inside an array?( )
- applies a filter/condition (script) expression.@
- current object@.srcID==3447
- the currect object which has child srcID
with value 3447
.key
- get the key of the object which satisfies the above conditionsI make an example, and config the JSON Extractor like above
And the result
For more usage about JSON Extractor, please refer:
Upvotes: 9
Reputation: 89
Here is the expression which will extract the value.
`$..[?(@.srcID=3447)].key`
Reference:
https://www.blazemeter.com/blog/advanced-usage-json-path-extractor-jmeter
Upvotes: 1