如何使用 JMESPath 创建条件节点

How to create a conditional node with JMESPath

使用基于以下内容的 JMESPath:

我可以创建输出但不能创建条件部分。似乎是一个简单的 if then else 但我找不到任何相关文档。

有什么建议吗?

您可以简单地使用 JMESPath 中条件的评估作为结果的值 JSON。

鉴于查询:

{output: {aslist: app.usertype == 'power'}}
  • 以您的示例为例JSON:
    { 
      "app": { 
        "usertype": "power" 
      } 
    }
    
    这会给
    {
      "output": {
        "aslist": true
      }
    }
    
  • 以您的示例为例JSON:
    { 
      "app": { 
        "usertype": "simple" 
      } 
    }
    
    这会给
    {
      "output": {
        "aslist": false
      }
    }
    

但是,当然,由于它是基于您的简化示例的条件的简单评估,它还会为您提供 false 任何不属于 usertype 的东西 [=17] =].