← Back to context

Comment by mickeyp

5 months ago

XPath is a superb query language for XML (or anything that you can structure as a DOM) --- it is also, with some obscure exceptions, the only query language with serious adoption, so it's an easy choice and readily available in XML tools. The only caveat is there are various spec versions and most never added support for newer versions.

Let's look at JSON by comparison. Hmm, let's see: JSONPath, JMESPath, jq, jsonql, ...

JQ is the most feature-rich of the bunch. It's defacto standard and I usually just default to it because it offers so much - assignment, various builtins such as base64 encoding.

The disadvantage is that it's not easily embeddable in your own programs - so programs use JSONPath / Go templates often.

  • I also don't think there's a specification written for the jq query language, unlike https://jmespath.org/ , which as you mentioned also has more client libraries.

    I too am probably going to embed jmespath in my app.I need it to allow users to fill CLI flags from config files, and it'll replace my crappy homegrown version ( https://github.com/bbkane/warg/blob/740663eeeb5e87c9225fb627... )

  • And it's yet another terrible DSL that you must learn when it could have been a language everybody already knows, like Python. The query part isn't even that well done, compared to XPath/JSONPath.

    I said goodbye to it a few weeks ago, personally (https://world-playground-deceit.net/blog/2025/03/a-common-li... https://world-playground-deceit.net/blog/2025/03/speeding-up...)

    • > And it's yet another terrible DSL that you must learn when it could have been a language everybody already knows, like Python.

      Oh, yeah, I 100% want to type this 15 times a day

        # I'll grant you the imports, in the spirit of fairness
        aws ec2 describe-instances | python -c '
          for r in json.load(sys.stdin)["Reservations"]:
            print("\n".join(i["PrivateIpAddress"] for i in r["Instances"]))
        '
      

      because that is undoubtedly better than

        aws ec2 describe-instances | jq -r '.Reservations[].Instances[].PrivateIpAddress'
      

      I mean, seriously, who can read that terrible DSL with all of its line noise

      > The query part isn't even that well done, compared to XPath/JSONPath.

      XPath I'll grant you, because it's actually very strong but putting JSONPath near jq in a "could be improved" debate tells me you're just not serious. JSONPath is a straight up farce

      1 reply →

Recently discovered Jsonata thanks to AWS adding it to Step Functions. Feel free to add it to your enumeration