如何根据条件停止管道 jq 执行?
How to stop pipe jq execution based on condition?
使用 ActiveCampain 工作流程,我有一个管道,我想在其中根据 jq 命令的输出有条件地执行代码。
例如,我想执行 !http
和 !jq
命令 if .status == "event-created"
.
JSON
{
"id":1,
"firstname": "Nj",
"lastname": "Bhanushali",
"email": "test@test.com",
"title":"Call with new lead",
"status":"event-created"
}
代码
"!pipe": [
{
"!jq": ".status"
},
//call this jq if .status == "event-created"
{
"!http": {
"method": "GET",
"path": "/contact/fields"
}
},
{
"!jq": "${piped_content::1}"
},
]
快速查看文档表明有一个 !switch
您可以使用的“命令”。
{
"!switch": {
"jq": "if .status == \"event-created\" then 0 else 1 end",
"cases": [
{
"!pipe": [
{
"!http": {
"method": "GET",
"path": "/contact/fields"
}
},
{
"!jq": "${piped_content::1}"
}
]
},
{
}
]
}
}
备注:
我不知道其中一种情况下使用空散列是否可以接受。也许你必须使用 null
?也许你必须忽略它?如果你省略它,也许你必须使用if .status == "event-created" then 0 else empty end
?如果可行,那将是最干净的解决方案。根据需要进行调整。
我不知道 ${piped_content::1}
我所做的更改是否仍然正确。根据需要进行调整。
使用 ActiveCampain 工作流程,我有一个管道,我想在其中根据 jq 命令的输出有条件地执行代码。
例如,我想执行 !http
和 !jq
命令 if .status == "event-created"
.
JSON
{
"id":1,
"firstname": "Nj",
"lastname": "Bhanushali",
"email": "test@test.com",
"title":"Call with new lead",
"status":"event-created"
}
代码
"!pipe": [
{
"!jq": ".status"
},
//call this jq if .status == "event-created"
{
"!http": {
"method": "GET",
"path": "/contact/fields"
}
},
{
"!jq": "${piped_content::1}"
},
]
快速查看文档表明有一个 !switch
您可以使用的“命令”。
{
"!switch": {
"jq": "if .status == \"event-created\" then 0 else 1 end",
"cases": [
{
"!pipe": [
{
"!http": {
"method": "GET",
"path": "/contact/fields"
}
},
{
"!jq": "${piped_content::1}"
}
]
},
{
}
]
}
}
备注:
我不知道其中一种情况下使用空散列是否可以接受。也许你必须使用
null
?也许你必须忽略它?如果你省略它,也许你必须使用if .status == "event-created" then 0 else empty end
?如果可行,那将是最干净的解决方案。根据需要进行调整。我不知道
${piped_content::1}
我所做的更改是否仍然正确。根据需要进行调整。