JsonSQL


Thanks to Harry over at Code Bus we now have a PHP version of JsonSQL. For those not familiar with JsonSQL, it allows you to use basic SQL syntax to parse json. Supported syntax includes selects, order by, where, and limit and allows you to apply conditions on objects of any depth within the json or array and return an array of the objects selected. Where clauses are not sql conditions, but conditions from Javascript(or PHP in this conversion), so you have full access to that language’s functions.

After a bit of work it is now possible to use sql to parse json using javascript!. I introduce to you version 0.1 of JsonSQL. Given a javascript object you can write a simple select statement to filter, order and limit the object:

jsonsql.query("select title,url from json.channel.items
where (category=='javascript' || category=='vista')
order by title,category asc limit 3",json);

Give it a shot. It would be nice to expand this a little more with a few aggregate functions (distinct, count, etc..).