Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case-insensitive search with JMESPath

The question is simple. How to do a case-insensitive searching with JMESPath?

Let's say to search for foo in this JSON:

[
  "foo",
  "foobar",
  "barfoo",
  "bar",
  "baz",
  "barbaz",
  "FOO"
]

Here is the case-sensitive search query:

[?contains(@, 'foo')]

It will returns ["foo", "foobar", "barfoo"] but it misses "FOO".

like image 800
HKTonyLee Avatar asked Dec 06 '25 02:12

HKTonyLee


1 Answers

[?contains(lower(@), lower('string_you_want_to_search')]

We could convert both search strings into lower or upper case to get case insensitive search.

https://jmespath.site/#preview Latest preview has support for it.

JEP discussion https://github.com/jmespath-community/jmespath.spec/discussions/21

like image 65
Ganesh Avatar answered Dec 08 '25 02:12

Ganesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!