Filtering JMESPath with contains
Asked Answered
B

1

7

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

Using its own example given from http://jmespath.org/

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

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

Brigandine answered 9/6, 2018 at 13:47 Comment(0)
L
12

Filtering by character and by string works the same.


query locations w/ names containing "l"

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

Result:

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

query locations w/ names containing "le"

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

Result:

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

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

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

Result:

[
  {
    "name": "Bellevue",
    "state": "WA"
  },
  {
    "name": "Olympia",
    "state": "WA"
  }
]
Lantana answered 13/6, 2018 at 7:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.