A means of filtering selections #18

lloyd opened this Issue Jun 3, 2011 · 4 comments


None yet

4 participants

lloyd commented Jun 3, 2011

Suggested by @dunkfordyce , implementation discussed here:

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 commented Jun 5, 2011

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

lloyd commented Jun 6, 2011

decisive. good.


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 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

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