8 methods for querying json Data Structures

Source: Internet
Author: User

Have you ever worried about "Searching for Matching content in complicated JSON data structures"? This article introduces eight ways to query json data structures, there is always a method suitable for your project

The following eight methods can be used to query json data structures: JsonSQL allows you to query json data structures using SQL select statements. Home page: http://www.trentrichardson.com/jsonsql/ example: the code is as follows: jsonsql. query ("select * from json. channel. items order by title desc ", json); JSONPath is like an XPath for the json data structure. Home page: http://goessner.net/articles/JsonPath/ example: Code: jsonPath (books, '$ .. book [(@. length-1)] ') jfunk jFunk allows you to retrieve complex JSON or Javascript objects (which will be added soon. The Design of jFunk API is almost similar to that of jQuery API. It directly copies jQuery APIs, except those for DOM APIs. Example: The Code is 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 functions to implement previous ideas, greatly improving the way you use data in Javascript. Example: The Code is as follows: var kelly = friends ({id: 2 }). first (); linq. js linq. the following code shows the Javascript-based LINQ code: var queryResult2 = Enumerable. from (jsonArray ). where ("$. user. the id <200 "). orderBy ("$. user. screen_name "). select ("$. user. screen_name + ':' + $. text "). toArray (); objeq is a simple library that enables Real-Time query of POJSO (Plain-Old JavaScript Objects, common Javascript Objects. Home: https://github.com/agilosoftware/objeq code: var res = $ objeq (data, "age> 40 & gender = 'female '-> name "); // --> Returns ['jessica '] (Note: it uses Javascript property setters, so it can only work on newer browsers) json: select () use the class CSS selector to query JSON. Home page: http://jsonselect.org/#tryit code:. lang: val ("Bulgarian ")~. Level Paul programming Pearl Javascript Array filtering method, Home Page: http://www.paulfree.com/28/javascript-array-filtering/#more-28 code is as follows: var a = [,]; // return everythinga. where ("() => true"); // --> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // return even numbersa. where ("(n, I) => n % 2 = 0"); // --> [2, 4, 6, 8, 10] // query first 6 products whose category begins with 'Con 'using extra param and regular expressionproducts. w Here ("(el, I, res, param) => res. length <= 6 & param. test (el. cat) ",/^ con/I); // using customer table data from SQL Server's northwind database... MERs. where ("(el, I, res, param) => el. country = param "," USA "); currently, this is my favorite method for querying JSON data structures. It is very simple and, according to the author, it is very fast. The idea behind it is similar to John Resig's JavaScript Micro-Templating: use the correct expression to convert a very simple string into a Javascript function. Of course, there are more powerful solutions. The prototype implemented by Paul still lacks the syntax check for the filter expression, but I believe you can solve the Javscript syntax check yourself.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.