Re:JSONiq: JSON Query Language
by Felk on Tuesday November 09, 2021 @04:36AM
(#29159504)
Can someone explain to me what the main differences to jq are, besides the syntax?
[ Parent
| on HN ]
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.
Re:JSONiq: JSON Query Language
by EdwardDiego on Tuesday November 09, 2021 @05:12AM
(#29159748)
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.
Re:JSONiq: JSON Query Language
by emmanueloga_ on Tuesday November 09, 2021 @05:55AM
(#29160057)
... although, it seems neither JSONIq nor jq contain a "parent" operator, as far as I can tell.
Re:JSONiq: JSON Query Language
by lichtenberger on Tuesday November 09, 2021 @09:58AM
(#29162567)
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"?
it's senseless besides nit-picking.
that's just like your opinion man.
Re:JSONiq: JSON Query Language
by jbverschoor on Tuesday November 09, 2021 @06:49AM
(#29160407)
> JSONiq borrows a large numbers of ideas from XQuery
So basically grep or even sql ->xquery. No thank you!