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

Provide a sorted operator #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cdent
Copy link

@cdent cdent commented May 21, 2015

This sorts (using python sorted) the current object's value if it is a
list or dict and returns the list or keys.

This is presented a strawman proposal for doing sorts as I couldn't
decide how to do it correctly. At least with some starting code maybe
we can reach something better.

Note that the goal here is to get a sorted list of atomic entities
which can be evalauted, not to sort a collection of objects by a key
of those objects. That would be useful too, and presumably there is a
way to do it generically.

The demonstrated syntax is:

foo.sorted

presumably things like like:

foo.[/] # ascending sort of this
foo.[] # descending sort of this
foo.[/somekey] # ascending sort by somekey's value

ought to be possible but I do not know if it is aligned with proper
JSONPath.

This sorts (using python sorted) the current object's value if it is a
list or dict and returns the list or keys.

This is presented a strawman proposal for doing sorts as I couldn't
decide how to do it correctly. At least with some starting code maybe
we can reach something better.

Note that the goal here is to get a sorted list of atomic entities
which can be evalauted, not to sort a collection of objects by a key
of those objects. That would be useful too, and presumably there is a
way to do it generically.

The demonstrated syntax is:

   foo.`sorted`

presumably things like like:

   foo.[/]        # ascending sort of this
   foo.[\]        # descending sort of this
   foo.[/somekey] # ascending sort by somekey's value

ought to be possible but I do not know if it is aligned with proper
JSONPath.
@cdent
Copy link
Author

cdent commented May 21, 2015

I don't expect this to be merged, it's just a bit of code to help think about sorting as discussed in #7 and #8. With some assistance I should be able to get us to something that works and is appropriate.

@kennknowles
Copy link
Owner

You know, I actually prefer this to the JSONQuery syntax.

kaapstorm pushed a commit to kaapstorm/python-jsonpath-rw that referenced this pull request Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants