8 ways to query the data structure of JSON:
Jsonsql
Jsonsql implements the ability to query using SQL SELECT statements in the JSON data structure. Home: http://www.trentrichardson.com/jsonsql/
Example:
Copy Code code as follows:
Jsonsql.query ("SELECT * from Json.channel.items ORDER BY title DESC", JSON);
Jsonpath
Jsonpath is like XPath for the JSON data structure. Home: http://goessner.net/articles/JsonPath/
Example:
Copy Code code as follows:
Jsonpath (books, ' $ ... book[(@.length-1)]
Jfunk
Jfunk allows you to retrieve complex JSON or JavaScript objects (which will soon be added to the admin function). The Jfunk API is designed almost like the jquery API. It directly replicates the jquery API, in addition to those for DOM.
Home: http://code.google.com/p/jfunk/
Example:
Copy Code code as follows:
Jf ("> Vegetables > *[color=orange]", Food). get ();
Taffydb
Have you ever noticed that the literal value of a JavaScript object looks like a record? If you wrap them in an array, do they look like a database table? Taffydb is a JavaScript library that provides powerful database capabilities to implement previous ideas, dramatically improving the way you use data in JavaScript.
Home: http://www.taffydb.com/
Example:
Copy Code code as follows:
var Kelly = Friends ({id:2}).
Linq.js
LINQ in Linq.js--javascript
Copy Code code as follows:
var queryResult2 = Enumerable.from (Jsonarray)
. Where ("$.user.id < 200")
. by ("$.user.screen_name")
. Select ("$.user.screen_name + ': ' + $.text")
. ToArray ();
Objeq
Objeq is a simple library that implements real-time queries for POJSO (plain-old JavaScript Objects, normal JavaScript objects). Home: Https://github.com/agilosoftware/objeq
Copy Code code as follows:
var res = $objeq (data, age > && gender = = ' female '-> name ');
--> Returns [' Jessica ']
It uses JavaScript's property setters, so it works only on newer browsers.
Json:select ()
Use the class CSS selector to query for JSON. Home: http://jsonselect.org/#tryit
Copy Code code as follows:
. Lang:val ("Bulgarian") ~ Level
The JavaScript array filtering method in Paul's programming Zhuji , home: http://www.paulfree.com/28/javascript-array-filtering/#more-28
Copy Code code as follows:
var a = [1,2,3,4,5,6,7,8,9,10];
return everything
A.where ("() => true");
--> [1,2,3,4,5,6,7,8,9,10]
return even numbers
A.where ("(N, i) => n% 2 = 0");
--> [2,4,6,8,10]
Query 6 whose category begins with ' con ' using extra param and regular expression
Products.where ("(El, I, res, param) => res.length <= 6 && param.test (el.cat)",/^con/i);
Using Customer table data from SQL Server ' Northwind database ...
Customers.where ("(El, I, res, param) => el.country = = param", "USA");
Now this is my favorite way to query the JSON data structure. It's very simple, and according to the author, it's very fast.
The idea behind it is similar to that of John Resig's JavaScript micro-templating: Converting a very simple string into a JavaScript function using the correct expression.
There are, of course, more powerful solutions. The prototype Paul implements also lacks a syntax check on the filter expression, but I believe you should be able to solve the javscript grammar check yourself.