JSONSelect
jsonselect.org
jsonselect.org
stuff = {
"author": {
"name": {
"first": "Lloyd",
"last": "Hilaiel"
},
"drinkPref": [
"whiskey",
"beer",
"wine"
],
},
"thing": "JSONSelect site",
"license": "(cc) BY-SA"
}
stuff.author.drinkPref[0]
> "whiskey"I think I'd prefer something more XPath-like than CSS myself (as someone linked in another comment)
Naming it might be tricky though.
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).[1]: https://developer.mozilla.org/en/JavaScript/Reference/Global...
With normal javascript you would get an exception .. hopefully with this you just get back undefined without having to check every step in the path.
JSONSelect.match(".nonexistantkey .somechild", obj) returns []
Alternately, if you use the JSONSelect.forEach() method your callback will just not be invoked.
So no existence testing before access for recursive values. A main benefit of this thing in javascript.
http://goessner.net/articles/JsonPath/
These tools could be fun for writing map functions for CouchDB.
http://www.sitepen.com/blog/2010/11/02/resource-query-language-a-query-language-for-the-web-nosql/Great.
I think web developers get caught up in bashing XML a lot for no good reason - just because it isn't directly applicable to a simple RESTful API doesn't mean it isn't incredibly useful, it's meant for machines anyway!
But no, XML wasn't meant for machines... its just that people today programatically generate and consume XML far more often than they do it by hand.
http://www.sitepen.com/blog/2010/11/02/resource-query-langua...
There's an Arel-style JS implementation to build RQL strings using chained methods, which makes it quite conducive to composition and makes it feel more like functional programming.
Along those lines are D3's selections:
http://mbostock.github.com/d3/#selections
... and jLinq http://www.hugoware.net/Projects/jLinqFor "real" CSS in particular, I prefer a bit of verbosity over awk-like code. And you should likely be using a CSS generator anyway, it doesn't even have variables, for Knuth's sake :/