jsoniq

How do I fix the Jsoniq static error: invalid expression: syntax error, unexpected "every"?


I am performing this query to see if there is any multimedia software packages available in this pretend database

let $swpackages := [
    {"name": "flimber", "version": 1.8, "category": "admin"},
    {"name": "quack", "version": 5.4, "category": "admin"},
    {"name": "xyz", "version": 3.118, "category": "admin"},
    {"name": "grop", "version": 11, "category": "editor"},
    {"name": "snarl", "version": 3.0, "category": "editor"},
    {"name": "rope", "version": 1.45, "category": "devel"},
    {"name": "crunch", "version": 11.53, "category": "devel"},
    {"name": "quickdelete", "version": 4.8, "category": "util"},
    {"name": "readmind", "version": 2.34, "category": "util"},
    {"name": "slurp", "version": 12.5, "category": "multimetia"},
    {"name": "yaf", "version": 1.1, "category": "multimedia"},
    {"name": "noodle", "version": 11, "category": "multimedia"}
]

I have this information saved in another file called packages.sq. I am performing following query:

 jsoniq version "1.0";
 let $packages := { (: packages.jq :) }    
 every $sw in $packages.swpackages[] satisfies
    (some $package in $packages.swpackages.category[]
          satisfies $cat eq "multimedia")

There doesn't seem to be a lot of resources about jsoniq and i am a noob with this query language. Any tips on how to fix my error would be greatly appreciated. Thanks!


Solution

  • There were two issues:

    1. a let clause must always be used with a matching return clause (these are FLWOR expressions). Generally clauses can be in almost any order, but always with a concluding return clause.
    2. The nested variable was inconsistent, it should be changed to some $cat)

    This leads to the following query, which should parse (it parses on the RumbleDB sandbox).

    let $packages := { (: packages.jq :) }   
    return every $sw in $packages.swpackages[]
           satisfies (some $cat in $packages.swpackages.category[]
                      satisfies $cat eq "multimedia")