Hacker News new | ask | show | jobs
by Felk 1680 days ago
Can someone explain to me what the main differences to jq are, besides the syntax?
5 comments

jq seems to have more focus on the generator and pipe abstractions. In jq you say "foo | map(bar)"; foo and map(bar) are both generators, and bar refers to each element of foo as ".". Here you say "for $x in foo return bar"; foo and bar are both JSON objects, and bar refers to each element of foo as "$x", so the iteration is more explicit.

Likewise, compare "sum($element.response_time)" with "map(.response_time) | add" in jq. Processing in JSONiq goes inside to outside while jq goes left to right.

My first thought also - would be a good entry for a FAQ or blog post.
Jq is xpath, this looks to be xquery. In fact it specifically works as an xquery embed.
You can write the example below in jq as

    def avg: add / length;
    group_by(.url) | map({
      "url": .[0].url,
      "hits": length, 
      "avg": map(.response_time) | avg
    })
so jq should be (at least roughly) as powerful as JSONiq.
... although, it seems neither JSONIq nor jq contain a "parent" operator, as far as I can tell.
This might be too restricting regarding the storage.

But we have a function: https://github.com/sirixdb/brackit

Not that not having it makes either of them any less powerful. If you descend to an inner context, you can refer to the parent/ancestor via a variable you can set before-hand.
For one thing, modifying data I guess.
What do you mean? jq can modify data:

  $ jq '.foo += 1' <<< '{"foo": 2}'
  {
    "foo": 3
  }
looks nothing like jq

  1. let $stats := collection("stats")
  2. for $access in $stats
  3. group by $url := $access.url
  4. return 
  5. {
  6.   "url": $url,
  7.   "avg": avg($access.response_time),
  8.   "hits": count($access)
  9. }
> besides the syntax
isn't that question like "cinema besides the movies"?
the user experience. jq is often a one liner, terse and expressive. This jsoniq language looks almost like a scripting language, requiring multiple lines to write an expression.
I have multiple 30+ lines jq scripts in my current project. So "often a one liner" is true, but it is not a requirement, so I'm still not sure why use this instead.
no, language is not just syntax.
Nor is the cinema just movies.
so if cinema isn't just movies then what's the problem with asking about the difference in "cinema besides the movies"?
> JSONiq borrows a large numbers of ideas from XQuery

So basically grep or even sql ->xquery. No thank you!