A means of filtering selections #18

Open
lloyd opened this Issue Jun 3, 2011 · 4 comments

Projects

None yet

4 participants

@lloyd
Owner
lloyd commented Jun 3, 2011

Suggested by @dunkfordyce , implementation discussed here:
http://librelist.com/browser//jsonselect/2011/6/3/objects/#b8bb946b3b839bd5894d9f78a5c6fb2fh

What if you want to limit the amount of data that's selected by your selector? A concrete case is when selecting a subset of twitter's api which return HUGE JSON OBJECTS with lots of stuff that YOU PROBABLY DONT CARE ABOUT

The proposal is to add two functions, one which discards items matching a selector, and the other which discards items not matching a selector. Naming is up in the air a bit, here are options:

  • :only() and :without()
  • :include() and :exclude()
  • :reduce() and :remove()
  • :limit() and :filter()
  • some permutation of the above...

These functions take a selector as an argument (like :has()), they do not affect the selection algorithm at all, but are applied after elements are selected and modify the return value.

for instance, given the document:

{
    "first": "Lloyd",
    "middle": "Trevor",
    "last": "Hilaiel"
}

both :root:only(.first,.last) and :root:remove(.middle) would return:

{ "first": "Lloyd", "last": "Hilaiel" }
@rwaldron
rwaldron commented Jun 5, 2011

Of the options above, I think that :include() and :exclude() are fairly comprehensive and semantically sound

@lloyd
Owner
lloyd commented Jun 6, 2011

decisive. good.

@dunkfordyce

just to mention: iv not given up the topic, im still in pondering mode! I think im more leaning to this sort of functionality in a differnt libray. ie, goiing back to my xpath/xslt comparison

@studgeek
studgeek commented Apr 6, 2012

Also check out XQuery since it introduced the idea of modifying the result set over XPath.

Really once you start wanting to change the results you need something that templates the final result, like XSL and XQuery had. In JavaScript/JSON you can obviously use a literal for that. JSONiq shows some good examples of how it could look
www.w3.org/2011/.../Documentation-0.1-JSONiq-Article-en-US.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment