8 ways to query JSON's data structure

Source: Internet
Author: User
Tags data structures json regular expression javascript array

  Have you bothered to "find matches in a complex JSON data structure", this article describes 8 ways to query JSON's data structure, and there's always a way to use it for your project

8 ways to query JSON's data structures:   Jsonsql   JSONSQL implements the ability to query using SQL SELECT statements in the JSON data structure. Home: http://www.trentrichardson.com/jsonsql/  Example:     code as follows: Jsonsql.query ("SELECT * FROM Json.channel.items ORDER BY title DESC ", JSON);     Jsonpath   Jsonpath is like XPath for JSON data structures. Home: http://goessner.net/articles/JsonPath/  Example:   code as follows: Jsonpath (books, ' $ ... book[(@.length-1)]     Jfunk   Jfunk allows you to retrieve complex JSON or JavaScript objects (which will soon add administrative functionality). The Jfunk API is designed almost like the jquery API. It directly replicates the jquery API, in addition to those for DOM.   Example:     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.   Example:     code is as follows: var Kelly = Friends ({id:2}). The LINQ code in     Linq.js   Linq.js--javascript is as follows: var queryResult2 = Enumerable.from (jsonarray)    . Where ("$.user.id <")   . 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     Code as follows: var res = $OBJEQ (data, age > && gender = = ' FEM Ale '-> 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     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     code is 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 products whose category begins with ' Con ' using extrA param and regular expression products.where (el, I, res, param) => res.length <= 6 && param.test (el.c at) ",/^con/i); Using Customer table data from SQL Server ' Northwind database ...     Customers.where (EL, I, res, param) => el.country = = param "," USA ");     This is my favorite way to query the JSON data structure at this time. 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.  

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.