8 ways to query JSON data structures

Source: Internet
Author: User
Tags javascript array asymmetric encryption

8 ways to query JSON data structures

2012/12/14 | classification:   it technology ,  web Front end ,  development  |  0 reviews Bole online javascript

Share to: Ten
    • Java for asymmetric encryption
    • data storage, components and gestures in Android
    • Introduction to Java second season
    • Android Customize any level tree control

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:

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

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

JSONPath

Jsonpath is like an XPath for a JSON data structure.

Example:

1 jsonpath (Books, ' $ '). book[(@.length-1)] ')

Home page: 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:

1 JF ("> Vegetables > *[color=orange]", food). get ();

Home page: 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.

1 varkelly = Friends ({Id:2}). First ();

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

Linq.js

Linq.js--javascript in LINQ (Translator Note: The concepts in. NET, see http://msdn.microsoft.com/zh-tw/library/bb397897 )

1 2 3 4 5 varqueryResult2 = Enumerable.from (Jsonarray)     . Where ("$.user.id <") . ("$.user.screen_name") . Select ("$.user.screen_name + ': ' + $.text") . ToArray ();

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

Home page: 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).

1 2 varres = $objeq (data, "Age > && gender = = ' female '); /--Returns [' Jessica ']

Home page: 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.

1 .lang:val ("Bulgarian") ~. Level

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

The JavaScript array filtering method in Paul's programming Zhu Ji Nanxiong
1 2 3 4 5 6 7 8 9 Ten One A - - the - - - + - + vara = [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 expression   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 page: 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 and John Resig's JavaScript micro-templating similar: Use 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.

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.