JMeter - JSON 路径表达式:提取包含元素的 JSON 块和包含多个条件的正则表达式
JMeter - JSON path expressions: Extract JSON block with elements and regex with multiple conditions
我想提取 JSON 满足多个条件的块。例如,提取一个块,该块的变量具有两个或多个所需值。请参阅下面给出的示例。
[
{
id:"1",
name:"ABC - Project 1",
appName:"XYZ",
state:"New",
appType:"owner",
date:"May 12"
},
{
id:"2",
name:"DEF - Project 2",
appName:"UVW",
state:"In Progress",
appType:"manager",
date:"May 13"
},
{
id:"3",
name:"GHI - Project 3",
appName:"RST",
state:"In Progress",
appType:"owner",
date:"May 12"
},
{
id:"4",
name:"JKL - Project 4",
appName:"OPQ",
state:"Expired",
appType:"entity owner",
date:"July 13"
}
]
从上面的 JSON,我想提取 JSON 块,其中状态:“进行中”或状态:“新建”,这些状态中的任何一个都应该是 appType:“所有者”连同姓名:...项目 1;即以下块作为输出:
{
id:"1",
name:"ABC - Project 1",
appName:"XYZ",
state:"New",
appType:"owner",
date:"May 12"
}
我应该使用哪些 JSON 路径表达式来提取:
$.[?((@.state == "In Progress" || @.state == "New") && @.appType== "owner" && <some regex expression>)]
但它没有提取任何结果。有没有办法对“OR/||”使用多个条件和“AND/&&”条件来提取该特定块。请帮忙!
谢谢,
席德
怎么样:
$.[?((@.state == "In Progress" || @.state == "New") && @.appType== "owner" && @.name =~ /.*Project 1.*/)]
=~
是一个 Filter Operator 允许指定正则表达式作为过滤条件
演示:
更多信息:JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios
我想提取 JSON 满足多个条件的块。例如,提取一个块,该块的变量具有两个或多个所需值。请参阅下面给出的示例。
[
{
id:"1",
name:"ABC - Project 1",
appName:"XYZ",
state:"New",
appType:"owner",
date:"May 12"
},
{
id:"2",
name:"DEF - Project 2",
appName:"UVW",
state:"In Progress",
appType:"manager",
date:"May 13"
},
{
id:"3",
name:"GHI - Project 3",
appName:"RST",
state:"In Progress",
appType:"owner",
date:"May 12"
},
{
id:"4",
name:"JKL - Project 4",
appName:"OPQ",
state:"Expired",
appType:"entity owner",
date:"July 13"
}
]
从上面的 JSON,我想提取 JSON 块,其中状态:“进行中”或状态:“新建”,这些状态中的任何一个都应该是 appType:“所有者”连同姓名:...项目 1;即以下块作为输出:
{
id:"1",
name:"ABC - Project 1",
appName:"XYZ",
state:"New",
appType:"owner",
date:"May 12"
}
我应该使用哪些 JSON 路径表达式来提取:
$.[?((@.state == "In Progress" || @.state == "New") && @.appType== "owner" && <some regex expression>)]
但它没有提取任何结果。有没有办法对“OR/||”使用多个条件和“AND/&&”条件来提取该特定块。请帮忙!
谢谢, 席德
怎么样:
$.[?((@.state == "In Progress" || @.state == "New") && @.appType== "owner" && @.name =~ /.*Project 1.*/)]
=~
是一个 Filter Operator 允许指定正则表达式作为过滤条件
演示:
更多信息:JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios