Github user afs commented on a diff in the pull request:
https://github.com/apache/jena/pull/114#discussion_r175909873
--- Diff: jena-arq/Grammar/master.jj ---
@@ -326,6 +361,46 @@ void AskQuery() : {}
SolutionModifier()
}
+#ifdef ARQ
+void JsonQuery() : {}
+{
+ JsonClause()
+ ( DatasetClause() )*
+ WhereClause()
+ SolutionModifier()
+}
+
+void JsonClause() : { Object o ; String s ; Token t; }
+{
+ <JSON> { getQuery().setQueryJsonType() ; }
+ <LBRACE>
+ s = String()
+ // PNAME_NS would eval true before COLON (default namescape) so we make
sure we got what we were expecting
+ t = < PNAME_NS > {
+ if ( ! t.image.equals(":") )
+ throwParseException("Prefix name expression not legal at this point
: "+t.image, t.beginLine, t.beginColumn) ;
+ }
+ (
+ o = Var() { getQuery().addResultVar((Var) o) ;
getQuery().addJsonMapping(s, o) ; }
+ | o = String() { getQuery().addJsonMapping(s, o) ; }
+ | o = Number() { getQuery().addJsonMapping(s, o) ; }
+ )
+ (
+ <COMMA> s = String()
+ t = < PNAME_NS > {
+ if ( ! t.image.equals(":") )
+ throwParseException("Prefix name expression not legal at this
point : "+t.image, t.beginLine, t.beginColumn) ;
+ }
+ (
+ o = Var() { getQuery().addResultVar((Var) o) ;
getQuery().addJsonMapping(s, o) ; }
+ | o = String() { getQuery().addJsonMapping(s, o) ; }
+ | o = Number() { getQuery().addJsonMapping(s, o) ; }
+ )
--- End diff --
Does not cover URIs, booleans or JSON null.
I tried `JSON { "F": "string" } WHERE {}` but got `[ {} ]` (one element, no
object fields) - which does not look right to me.
A bunch of tests calling a common function like `test(String query, String
jsonResult)` would help. e.g.
@Test public void json_query_01() { test("JSON { 'F': 'string' } WHERE
{}", "{ [ 'F' : 'string ] }" ; }
`JsonValue` supports structural `.equals`.
---