【问题标题】:Filtering JMESPath with contains使用包含过滤 JMESPath
【发布时间】:2018-11-19 08:36:27
【问题描述】:

JMESPath 是 Azure 使用的 JSON 查询语言。

使用http://jmespath.org/给出的自己的例子

{
  "locations": [
    {"name": "Seattle", "state": "WA"},
    {"name": "New York", "state": "NY"},
    {"name": "Bellevue", "state": "WA"},
    {"name": "Olympia", "state": "WA"}
  ]
}

如何列出名称中包含字母"l" 或字符串"le" 的所有位置?谢谢。

【问题讨论】:

    标签: json filter filtering jmespath


    【解决方案1】:

    按字符过滤和按字符串过滤是一样的。


    查询位置名称包含"l"

    locations[?name.contains(@, `l`)]
    

    结果:

    [
      {
        "name": "Seattle",
        "state": "WA"
      },
      {
        "name": "Bellevue",
        "state": "WA"
      },
      {
        "name": "Olympia",
        "state": "WA"
      }
    ]
    

    查询位置名称包含"le"

    locations[?name.contains(@, `le`)]
    

    结果:

    [
      {
        "name": "Seattle",
        "state": "WA"
      },
      {
        "name": "Bellevue",
        "state": "WA"
      }
    ]
    

    查询位置名称包含"ue""ia"

    locations[?name.contains(@, `ue`) || name.contains(@, `ia`)]
    

    结果:

    [
      {
        "name": "Bellevue",
        "state": "WA"
      },
      {
        "name": "Olympia",
        "state": "WA"
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-20
      • 2020-06-08
      • 1970-01-01
      • 2019-08-05
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多