如何基于另一个的值在Jmeter中提取json值 [英] How to extract a json value in Jmeter based on value of another
问题描述
在Jmeter中,我试图从json中提取值. 这是我收到的json响应:
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"
}
},
从上面的响应中,如果srcID = 3447,我想提取值"key". 我尝试这样做 $ .. cohortKey [?(@.srcCohortId = 3447)].cohortKey
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.
推荐答案
您可以使用 JSON Extractor 可以通过如下所示的JSON Path表达式来做到这一点:
You can use JSON Extractor to do this with the JSON Path expressions like below:
$..[?(@.srcID==3447)].key
其中:
-
..
-是递归的,它有助于在json数据中查找所有地方 -
[]
-数组,表示过滤器将在数组中应用并查找 -
?( )
-应用过滤器/条件(脚本)表达式. -
@
-当前对象 -
@.srcID==3447
-当前子对象为srcID
且值为3447
的当前对象
-
.key
-获取满足上述条件的对象的键
..
- 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
我举个例子,并像上面一样配置JSON提取器
I make an example, and config the JSON Extractor like above
结果
有关JSON提取器的更多用法,请参阅:
For more usage about JSON Extractor, please refer:
- JSON Extractor in JMeter
- JMeter basic
这篇关于如何基于另一个的值在Jmeter中提取json值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!