News for hackers. Stuff that matters.
Re:JSONSelect by kalleboo on Saturday May 21, 2011 @07:01AM (#2570659)
Their site has a pretty bad example. Instead imagine it's an array of authors instead. Then their selector would give you a list of all their favourite drinks, which would require a loop in normal JS.

I think I'd prefer something more XPath-like than CSS myself (as someone linked in another comment)

Re:JSONSelect by sambeau on Saturday May 21, 2011 @08:51AM (#2570785)
I'd love to see a javascript+json version of xquery. It would rock as a templating language.

Naming it might be tricky though.

Re:JSONSelect by riffraff on Saturday May 21, 2011 @09:27AM (#2570831)
there is a minimal spec, and implementations, of JSONPath, which may be enough for you
Re:JSONSelect by alinajaf on Saturday May 21, 2011 @12:31PM (#2571102)
Couldn't this be done with a simple map function? Not sure the exact javascript but in ruby it would be as simple as:

  favourite_drinks = authors.map { |a| a[:favourite_drink] }
Internally I'd imagine the language will have to loop through the json anyway. Are there any other benefits I'm missing (apart from of course the nice css-like syntax, which is perfectly valid).
Re:JSONSelect by Groxx on Saturday May 21, 2011 @12:37PM (#2571110)
It could be, yes. `map` isn't built-in on all browsers, though, which I think has hurt its use. i.e., most people don't think about it, so it doesn't get used as often.
Re:JSONSelect by subbu on Saturday May 21, 2011 @01:33PM (#2571222)
Underscore.js and Prototype.js both define this function. You can include this and use map. Underscore delegates it to ECMAScript 5's native map if available.
Re:JSONSelect by Groxx on Saturday May 21, 2011 @05:40PM (#2571809)
It's definitely 'out there', and you can always just copy-paste to get the same code and delegation[1], but the lack of default availability is a pretty damaging blow. It shouldn't be, but the Javascript world isn't exactly a pantheon of high-quality code.

[1]: https://developer.mozilla.org/en/JavaScript/Reference/Global...