如何根据另一个值在 Jmeter 中提取 json 值 [英] How to extract a json value in Jmeter based on value of another
问题描述
在 Jmeter 中,我试图从 json 中提取值.这是我收到的 json 响应:
<代码> {定义: {钥匙:1124,编号:1743,srcID: "3427",pcKey:-1,用户名:abraizada",cName: "JMeter2016-11-27-1480283993838",类型:主题",cohortTool: "Web 应用程序",cCount: 74,提取状态:已完成",日期创建:2017-05-09T18:35:35Z"},数据源: {编号:2,名称:索赔-OMOP",主题数:116352},项目: {编号:747,名称:Jmeter项目"}},{队列定义:{钥匙:1123,编号:1742,srcID: "3447",pcKey:-1,用户名: "IE_USER",cName: "JMeter2016-11-15-1479204865900",类型:主题",cohortTool: "Web 应用程序",cCount: 74,提取状态:",日期创建:2017-05-09T18:35:35Z"},数据源: {编号:2,name: "外部",sCount:116352},项目: {编号:747,名称:Jmeter项目"}},
从上面的响应中,如果 srcID=3447,我想提取值key".我试过这样做$..cohortKey[?(@.srcCohortId = 3447)].cohortKey
但没有得到结果.任何人都可以帮助我根据条件提取关键"值.
您可以使用 莉>
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.
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 childsrcID
with value3447
.key
- get the key of the object which satisfies the above conditions
I make an example, and config the JSON Extractor like above
And the result
For more usage about JSON Extractor, please refer:
这篇关于如何根据另一个值在 Jmeter 中提取 json 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!