[Reprint] 8 ways to query JSON data structures

Source: Internet
Author: User
Tags javascript array

http://wangxinghaoaccp.blog.163.com/blog/static/1158102362012111812255980/

Have you ever bothered to "find matches in complex JSON data structures"? There are 8 different ways to do this:

Jsonsql

Jsonsql implements the ability to query JSON data structures using SQL SELECT statements.

Example:

Jsonsql.query ("SELECT * from Json.channel.items ORDER BY title DESC", JSON);

Home: http://www.trentrichardson.com/jsonsql/

JSONPath

Jsonpath is like an XPath for a JSON data structure.

Example:

JsonPath (books, ' $. book[(@.length-1)]

Home: http://goessner.net/articles/JsonPath/

Jfunk

Jfunk allows you to retrieve complex JSON or JavaScript objects (which will soon be added to the management function). The Jfunk API is designed almost like the jquery API. It replicates the jquery API directly, except for the DOM-specific APIs.

Example:

Jf ("> Vegetables > *", food). get ();

Home: http://code.google.com/p/jfunk/

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 functionality to implement previous ideas, greatly improving the way you use data in JavaScript.

var Kelly = Friends ({Id:2}). First ();

Home: http://www.taffydb.com/

Linq.js

LINQ in Linq.js--javascript (Translator Note: Concepts in. NET, see HTTP://MSDN.MICROSOFT.COM/ZH-TW/LIBRARY/BB397897)

var queryResult2 = Enumerable.from (Jsonarray)     . Where ("$.user.id <")     . ("$.user.screen_name")     . Select ("$.user.screen_name + ': ' + $.text")     . ToArray ();

Home: http://linqjs.codeplex.com/

Home: http://neue.cc/reference.htm

Objeq

Objeq is a simple library that implements real-time querying of Pojso (Plain-old JavaScript Objects, ordinary JavaScript objects).

var res = $objeq (data, "age > gender && = = ' female ');     --Returns [' Jessica ']

Home: Https://github.com/agilosoftware/objeq

It uses the property setters of JavaScript, so it works only on newer browsers.

Json:select ()

Use the class CSS selector to query the JSON.

. Lang:val ("Bulgarian") ~. Level

Home: http://jsonselect.org/#tryit

The JavaScript array filtering method in Paul's programming Zhu Ji Nanxiong

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 first 6 products whose category begins with ' con ' using extra param and regular ex Pression          products.where ("(El, I, res, param) = res.length <= 6 && param.test (el.cat)",/^con/i); 
   //using Customer table data from SQL Server ' s Northwind database              ... Customers.where ("(El, I, res, param) = El.country = = param", "USA");

Home: http://www.paulfree.com/28/javascript-array-filtering/#more-28

This is my favorite way to query JSON data structures at this time. It's very simple, and according to the author, it's very fast.

The idea behind it is similar to John Resig's JavaScript micro-templating: Using the correct expression to convert a very simple string into a JavaScript function.

Of course, there are more powerful solutions. Paul's implementation of the prototype also lacks a syntax check of the filter expression, but I'm sure you should be able to solve the javscript grammar check yourself.

Finally, you have to decide which one is best for your project.

English Original: Orangevolt, compiling: Bole Online--Zhou Minhming

[Reprint] 8 ways to query JSON data structures

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.