I've been thinking about this as well, I think you are absolutely right.
Previously I had made some suggestions of JSON Query requirements [1]
and mentioned making it work with URIs, but I think that real adherence
to existing URI standards should be a primary goal. I would suggest
these as important goals:
* Properly adhere to the URI guidelines of rfc 3986 (rfc 2396)
* Make it simple to parse
* Make it properly superset application/x-www-form-urlencoded (rfc 1866
or 1867, I guess)
* Extensible, it should be easy for users to add custom functionality in
their query handlers.
As Jaanus points out, JSON Query operators forces important operators to
be encoded in URLs, essentially bypassing the whole intended structure
of query strings (and the delimiters described in 3986). Also, there are
plenty of form-urlencoded queries that would take on completely
different meanings in JSON query (or be invalid) due to the different
structure. These existing standards are far more important than
JSONPath, in reality. Consequently I would like to revamp, moving
towards a query format that would work with the standards compliance format.
Another format that is available for inspiration that I just found out
about, that very closely follows our goals, is the feed item query
language (FIQL) [2]. However, FIQL does not properly superset
application/x-www-form-urlencoded, so I don't think I would want to use
it as is.
So my basic proposal for future JSON query is this:
There are two types of terms, comparisons and calls. A comparison is of
the form name=value just like form urlencoding. Name and value are
encoded as components (instead quote delimited). Also the comparator is
not limited to =, but can include != and less than and greater than
comparators. A comparison should be interpreted as a filter on the
objects in a collection.
A call is of the form functionName(param1,param2). There will be several
predefined functions, including sort, group, distinct, and select, but
this is the main extension point, as users can have their own functions
with their own meanings.
Terms can be joined by & or | operators (meaning AND or OR, respectively).
I think this provides relatively easy to parse format, but is still easy
to extend.
One of the painful points of putting queries in URIs is that < and > are
not legal characters in URIs. Consequently here are some possibilities:
Current JSONQuery:
= - equal
%3C - less than
%3E - greater than
%3C= - less than or equal
FIQL:
== - equal
=lt= - less than
=gt= - greater than
=le= - less than or equal
My suggestion
= - equal
-+ - less than
+- - greater than
-=+ - less than or equal
Anyway here some examples and a start on ABNF for what I am thinking:
?foo=bar%20baz # property foo must be equal to "bar baz"
?price-+10 # property price must be less than 10
?price-+10&sort(-rating) # price under 10, sorted but rating in
descending order
?price-+10&select(brand)&distinct() # all the brands that have an object
with a price under 10
?foo=bar&tags.contains(fun)
?foo=bar&group(brand)&select(brand,average(price))
property = 1*pchar
property-path = property [ "." property-path ]
value = 1*pchar
comparator = ( "=" / "-+" / "+-" / "-=+" / "-=+" / "!=" )
comparison = property-path comparator value
logic = ( "&" / "|" )
function-parameter = ( value / expression )
function-parameters = function-parameter [ "," function-parameter ]
function-name = "sort" / "group" / "distinct" / "select" /
extension-function-name
function-path = property-path "." ( "contains" / extension-method-name )
extension-function-name = 1*pchar
extension-method-name = 1*pchar
named-function = ( function-name / function-path ) "("
function-parameters ")"
expression = ( comparison / named-function ) [ logic expression ]
query = expression
Let me know if you have any thoughts on this. Any preferences on
comparison operators (maybe FIQL style operators would be better, but
keeping equal as "=").
[1]
http://groups.google.com/group/json-query/web/json-query-requirements
[2]
http://tools.ietf.org/html/draft-nottingham-atompub-fiql-00
Thanks,
Kris
squashee wrote:
> Based on my experience from the current JSONquery implementation in
> dojotoolkit and the way it is used when querying resources i have a
> few suggestions.
>
> 1. Be sure to make it rfc2396 compliant, specifically, make it respect
> the reserved characters. Building backend for the current
> implementation requires sidestepping the normal handling of URI's and
> doing bad things� in order to accommodate the filter (?), sort (/) and
> map(=) operators.
>
> 2. Use specifications subsets and accept /negotiate partial compliance
> or capabilities. The current perservere implementation is quite
> elegant but also quite uncommon in it's nature being an object store.
> Looking at the current state of backend data sources most turn out to
> be relational databases, thus having additional limitations. Things
> like the recursive descent operator become quite hard to implement in
> a meaningful way and should thus be outside the spec or placed in a
> subet of capabilities.
>
> I'm currently in the process of finishing up development on a backend
> based on the PHP Doctrine ORM that delivers RESTful JSON and has
> limited JSONquery capability (based on the perservere/dojo work done
> by Kris Zyp).
>
> Jaanus Heeringson
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "json-query" group.
> To post to this group, send email to
json-...@googlegroups.com
> To unsubscribe from this group, send email to
json-query+...@googlegroups.com
> For more options, visit this group at
http://groups.google.com/group/json-query?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>