How to search with case insensitive regex using JMESPath [closed]
Asked Answered
D

1

22

I need to work with some systems that use JMESPath to search JSON. How can I search for strings with pattern (like this). How do I do this with a regular expression in case-insensitive mode?

P.S.: Not sure why AWS S3 CLI, and Ansible use JMESPath instead of jq to query JSON. It seems to be missing these features and the proposal to add split function has been frozen since 2017 (like this and this). These features are all available to jq. What are the strengths of JMESPath that make it appealing?

Debenture answered 18/6, 2021 at 18:29 Comment(0)
C
16

It's not so much about the difference between JMESPath and jq as the different ways they are used.

Suppose you are querying a remote resource, the result is going to number in the millions of records, but you only care about a specific, much smaller subset of the records. You have two choices:

  1. Have every record transmitted to you over the network, then pick out the ones you want locally
  2. Send your filter to the remote resource, and have it do the filtering, only sending you the response.

jq is typically used for the former, JMESPath for the latter. There's no reason why the remote service couldn't accept a jq filter, or that you couldn't use a JMESPath-based executable.

Controversial answered 18/6, 2021 at 20:13 Comment(11)
Thanks for your answer! This is getting interesting. I guess because jq is a Turing-complete language so it is less suitable to run arbitrary jq language in server-side. I am not familar with JMESPath but let me check if it is Turing-complete.Debenture
I should stress that my answer is based solely on how I see each used, and not so much on what either would be suitable for. Perhaps JMESPath is optimized to be simpler to write, but less powerful. (Or maybe JMESPath was more powerful when introduced, and so made people choose it as their query language, but jq caught up in the meantime.)Controversial
Or JMESPath puts an emphasis on filtering, while jq emphasizes transformation.Controversial
I searched some of the links in the Internet (e.g. github.com/serverlessworkflow/specification/issues/216, forum.snapcraft.io/t/…) they all mentioned JMESPath is lacking the features they needed. But no one said jq does not have features they needed. The only complain to jq is that it lacks a well-defined spec. I would assume JMESPath is less powerful than jq.Debenture
I agree your "JMESPath puts an emphasis on filtering, while jq emphasizes transformation" is a good summary.Debenture
I suspect the reason has to do with the fact that it is trivially easy to write jq programs that will consume as much CPU and/or RAM as is available. Consider e.g. range(0;infinite) or [range(0;infinite)]Firmament
Thanks @peak! That is a very good example. Attackers can easily DDOS servers that accept jqDebenture
Fortunately, jqplay.org has an execution timeout.Firmament
I am afraid this is not enough. That needs ulimit to restrict the memory usage as well. That means jq must be run in separated process.Debenture
Sending a jq filter to the server is a no-go because it is Turing Complete. Downvoted because you confidently say "There's no reason why ..." and won't fix it even though the first comment pointed out this issue.Weeds
I'm referring to techincal reasons. If the server wants to accept the risk of processing a non-terminating jq filter, it's free to do so.Controversial

© 2022 - 2024 — McMap. All rights reserved.