Say our JSON data comes from a single MySQL table:
someJSON = [ { name: 'bill' , sex:'M', income:50000 }, { name: 'sara' , sex:'F', income:100000 }, ... ];
And say the pseudo-code is:
"Get all the person objects of all sex:F
of income
> 60000`".
Are there any javascript libraries that would allow one to code such queries on this JSON data using a SQL or SQL-like syntax.
In case you are curious, some context:
I am making the front-end of a data analysis web service for my organization without knowing what the future backend will be. In the future they will migrate their data from MS Access tables to some-sort of MySQL-type database. Until then I am using static JSON files to start development and was thinking it may be helpful for them in the future to have my javascript queries appear as MySQL queries. (The current MS Access database is unreachable from the web.)
You can try alasql.js. It is pure JavaScript client-side SQL-server, where you can do queries over JSON objects.
// Fill table with data var data = [ { name: 'bill' , sex:'M', income:50000 }, { name: 'sara' , sex:'F', income:100000 }]; // Do the query console.log(alasql("SELECT * FROM ? WHERE sex='F' AND income > 60000",[data]));
Try this in Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With