Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand python-jsonpath-rw to support JSON Query (Feature request) #8

Open
ghost opened this issue Aug 1, 2013 · 9 comments
Open

Expand python-jsonpath-rw to support JSON Query (Feature request) #8

ghost opened this issue Aug 1, 2013 · 9 comments

Comments

@ghost
Copy link

ghost commented Aug 1, 2013

JSON Query is a superset of JSON Path that includes filtering, mapping and transformations: http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/

@kennknowles
Copy link
Owner

Very similar to #7 and thank you for the link. I have been convinced by you and @gregglind that many of these additions are worth trying.

I will probably implement this soon:

  • Sorting via [\expression]

I will happily accept pull requests for these features:

  • Filtering by [?expression]
  • String escaping (the important part of $1, $2, etc)
  • Mapping via [=expression] (but the language of the expression is going to be a lot of work for a feature that seems much less useful than filtering and sorting - very unlikely that I will bother with this)

Here are some things that need to be improved:

Instead of

+, -, /, *, &, |, %, (, ), <, >, <=, >=, != - These operators behave just as they do in JavaScript.

We need explicit documentation of the semantics of every operator, independent of the host language or any other scripting language.

This library is used for input into web sites, Excel formulae, SQL expressions, etc where the semantics of Python or JavaScript is neither relevant nor desirable. Dojo (like the original JSONPath write-up) could leave this out because of their audience and use cases.

In #7 I proposed that the best options were a consistent global ordering or crashing on type issues. JS-like semantics are a good third option, but we need to document them clearly here since there are a lot of inconsistencies (if you haven't read http://wtfjs.com/ you certainly should)

> 3 < "hello"
false
> "hello" < 3
false
> "hello" <= 3
false

This is actually quite useful for querying JSON as it implicitly will filter out values that do not match your assumptions, but since it is inconsistent with the actual meaning of < it needs to be called out. Similar issues will arise with each operator.

@prologic
Copy link

Having written a few JSON API9s) myself now in Python I'm more convinced of the need fr tools and libraries like this! I would +1 this but am still learning this library and whether or not it can solve by problem(s). Currently I am using jsonselect as a way of providing very naive querying capabilities on my API(s).

Since jsonselect cannot for me solve:

  • more complex queries like "give me a set of objects whose property xyz is a subset of the ["foo", "bar", "baz"].
  • sorting and general query filters and expressions

I'm also considing ObjectPath and JSONiq

@prologic
Copy link

Scratch JSONiq ;) Overkill and not really useful for Python nevermind it's endlessly deep complex dependencies, installation and usage :)

@prologic
Copy link

Sadly this library jsonpath_rw won't solve my problem at hand either namely due to this Issue #8 -- I already have fairly decent Path Traversal via jsonselect

@prologic
Copy link

+1 for JSON Query ;)

@kennknowles
Copy link
Owner

Are there particular pieces of JSONQuery you are most interested in? I've ended up working on other things lately, but the pieces of this which are well-defined and requested will likely be implemented at some point.

@prologic
Copy link

Can you shre what's coming in terms of "query/filtering" feature(s)?

James Mills / prologic

E: prologic@shortcircuit.net.au
W: prologic.shortcircuit.net.au

On Tue, Jun 10, 2014 at 2:10 PM, Kenn Knowles notifications@github.com
wrote:

Are there particular pieces of JSONQuery you are most interested in? I've
ended up working on other things lately, but the pieces of this which are
well-defined and requested will likely be implemented at some point.


Reply to this email directly or view it on GitHub
#8 (comment)
.

@cdent
Copy link

cdent commented May 21, 2015

Sorting via [\expression]

Has there been any progress on implementing sorting. I looked into doing it myself and it wasn't clear what to do. My inclination was to treat it as a sort of Slice but I didn't make much in the way of immediate headway so I thought I'd check here on the state of things. Is there any in progress code or can you point me in the right direction.?

@erikbgithub
Copy link

Have you guys tried ObjectPath? For me quite a few things from the docs didn't work like slices, or [*] so I just gave up on it for now.

sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 20, 2015
sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 20, 2015
sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 20, 2015
sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 20, 2015
sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 20, 2015
sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 20, 2015
sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 21, 2015
sileht added a commit to sileht/python-jsonpath-rw that referenced this issue Aug 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants