4 ms·
Can someone explain to me what the main differences to jq are, besides the syntax?
by Felk 5y ago
Can someone explain to me what the main differences to jq are, besides the syntax?
- baq 5y agolooks 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. }
- keymone 5y ago> besides the syntax
- jbverschoor 5y ago> JSONiq borrows a large numbers of ideas from XQuery So basically grep or even sql ->xquery. No thank you!
- mro_name 5y agoisn't that question like "cinema besides the movies"?
- keymone 5y agono, language is not just syntax.
- chii 5y agothe 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.
- _wolfie_ 5y agoI 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.
- EdwardDiego 5y agoMy first thought also - would be a good entry for a FAQ or blog post.
- masklinn 5y agoJq is xpath, this looks to be xquery. In fact it specifically works as an xquery embed.
- emmanueloga_ 5y ago... although, it seems neither JSONIq nor jq contain a "parent" operator, as far as I can tell.
- lichtenberger 5y agoThis might be too restricting regarding the storage. But we have a function: https://github.com/sirixdb/brackit https://github.com/sirixdb/brackit
- jolmg 5y agoNot 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.
- bonzini 5y agoYou 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.
- Deukhoofd 5y agoFor one thing, modifying data I guess.
- jolmg 5y agoWhat do you mean? jq can modify data: $ jq '.foo += 1' <<< '{"foo": 2}' { "foo": 3 }
- bonzini 5y agojq 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.