如何根据条件停止管道jq执行?

发布于 2025-01-11 15:30:05 字数 779 浏览 0 评论 0原文

使用 ActiveCampain 工作流程,我有一个管道,我想在其中根据 jq 命令的输出有条件地执行代码。

例如,如果 .status == "event-created",我想执行 !http!jq 命令。

JSON

{
    "id":1,
    "firstname": "Nj",
    "lastname": "Bhanushali",  
    "email": "[email protected]",  
    "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}"
    },
]

Using ActiveCampain work flows, I have a pipeline in which I want to execute code conditionally based on the output of a jq command.

For example, I want to execute and !http and !jq command if .status == "event-created".

JSON

{
    "id":1,
    "firstname": "Nj",
    "lastname": "Bhanushali",  
    "email": "[email protected]",  
    "title":"Call with new lead",
    "status":"event-created" 
}

Code

"!pipe": [
    {
        "!jq": ".status"
    },  
    //call this jq if .status == "event-created" 
    {
        "!http": {
            "method": "GET",
            "path": "/contact/fields"
        }
    },
    {
        "!jq": "${piped_content::1}"
    },
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许久 2025-01-18 15:30:05

快速查看文档表明有一个 !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 elseempty end?如果有效,那将是最干净的解决方案。根据需要进行调整。

  • 我不知道我所做的更改后 ${piped_content::1} 是否仍然正确。根据需要进行调整。

A quick look at the docs suggest there's a !switch "command" you can use.

{
  "!switch": {
    "jq": "if .status == \"event-created\" then 0 else 1 end",
    "cases": [
      {
        "!pipe": [
          {
            "!http": {
              "method": "GET",
              "path": "/contact/fields"
            }
          },
          {
            "!jq": "${piped_content::1}"
          }
        ]
      },
      {
      }
    ]
  }
}

Notes:

  • I don't know if it's acceptable to have an empty hash for one of the cases. Maybe you have to use null? Maybe you have to omit it? If you omit it, maybe you have to use if .status == "event-created" then 0 else empty end? If that works, that would be the cleanest solution. Adjust as necessary.

  • I don't know if ${piped_content::1} is still correct with the changes I've made. Adjust as necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文