News for hackers. Stuff that matters.
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?
Re:JSONiq: JSON Query Language by bonzini on Tuesday November 09, 2021 @09:27AM (#29162148)
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.
Re:JSONiq: JSON Query Language by masklinn on Tuesday November 09, 2021 @05:48AM (#29159996)
Jq is xpath, this looks to be xquery. In fact it specifically works as an xquery embed.
Re:JSONiq: JSON Query Language by bonzini on Tuesday November 09, 2021 @09:29AM (#29162175)
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

Re:JSONiq: JSON Query Language by jolmg on Tuesday November 09, 2021 @11:50AM (#29164069)
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.
Re:JSONiq: JSON Query Language by Deukhoofd on Tuesday November 09, 2021 @04:59AM (#29159655)
For one thing, modifying data I guess.
Re:JSONiq: JSON Query Language by jolmg on Tuesday November 09, 2021 @11:44AM (#29163996)
What do you mean? jq can modify data:

  $ jq '.foo += 1' <<< '{"foo": 2}'
  {
    "foo": 3
  }
Re:JSONiq: JSON Query Language by baq on Tuesday November 09, 2021 @04:46AM (#29159574)
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. }
Re:JSONiq: JSON Query Language by keymone on Tuesday November 09, 2021 @04:48AM (#29159583)
> besides the syntax
Re:JSONiq: JSON Query Language by mro_name on Tuesday November 09, 2021 @04:50AM (#29159593)
isn't that question like "cinema besides the movies"?
Re:JSONiq: JSON Query Language by chii on Tuesday November 09, 2021 @05:00AM (#29159664)
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.
Re:JSONiq: JSON Query Language by _wolfie_ on Tuesday November 09, 2021 @05:47AM (#29159985)
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.
Re:JSONiq: JSON Query Language by keymone on Tuesday November 09, 2021 @04:59AM (#29159654)
no, language is not just syntax.
Re:JSONiq: JSON Query Language by mro_name on Tuesday November 09, 2021 @05:11AM (#29159732)
Nor is the cinema just movies.
Re:JSONiq: JSON Query Language by keymone on Tuesday November 09, 2021 @06:29AM (#29160260)
so if cinema isn't just movies then what's the problem with asking about the difference in "cinema besides the movies"?
Re:JSONiq: JSON Query Language by mro_name on Tuesday November 09, 2021 @06:38AM (#29160327)
it's senseless besides nit-picking.
Re:JSONiq: JSON Query Language by keymone on Tuesday November 09, 2021 @07:00AM (#29160501)
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!