JSONSelect icon indicating copy to clipboard operation
JSONSelect copied to clipboard

A means of filtering selections

Open lloyd opened this issue 14 years ago • 4 comments

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

lloyd avatar Jun 03 '11 18:06 lloyd

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

rwaldron avatar Jun 05 '11 21:06 rwaldron

decisive. good.

lloyd avatar Jun 06 '11 22:06 lloyd

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

dunkfordyce avatar Jun 06 '11 22:06 dunkfordyce

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

studgeek avatar Apr 06 '12 19:04 studgeek