过滤JMESPath [英] Filtering JMESPath

查看:66
本文介绍了过滤JMESPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

JMESPath is a query language for JSON, used by Azure.

使用 http://jmespath.org/

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

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

How to list all locations whose name contains a letter "l", or a string "le"? thx.

推荐答案

按字符和字符串进行过滤的工作原理相同.

Filtering by character and by string works the same.

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

结果:

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


具有名称包含"le"

查询位置


query locations w/ names containing "le"

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

结果:

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


具有名称包含"ue""ia"

查询位置


query locations w/ names containing either "ue" or "ia"

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

结果:

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

这篇关于过滤JMESPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆