How to use Asp.net, MVC ,Jquery,SqlServer,Firebird,Java Script in computer Programming language
Monday, May 20, 2013
8 ways to query json structures
8 ways to query json structures
Do you get bored by complex JSON structure traversing to find just a bunch of matching entries ?
Here are 8 different ways to do it :
JsonSQL
JsonSQL implements SQL select statements over json structures.
Example:
jsonsql.query("select * from json.channel.items order by title desc",json);
Homepage: http://www.trentrichardson.com/jsonsql/
JSONPath
JSONPath is like XPath for JSON structures.
Example :
jsonPath( books, '$..book[(@.length-1)]')
Homepage: http://goessner.net/articles/JsonPath/
jfunk
jFunk will allow you to retrieve (and soon, manipulate) objects within complex JSON or Javascript objects. The design of the jFunk API will closely parallel the jQuery API, replicating it exactly except where the differences between DOM and Javascript make replication nonsensical
Example:
Jf("> vegetables > *[color=Orange]",Food).get();
Homepage: http://code.google.com/p/jfunk/
TaffyDB
How you ever noticed how JavaScript object literals look a lot like records? And that if you wrap a group of them up in an array you have something that looks a lot like a database table? TaffyDB is a libary to bring powerful database funtionality to that concept and rapidly improve the way you work with data inside of JavaScript.
var kelly = friends({id:2}).first();
Homepage: http://www.taffydb.com/
linq.js
linq.js - LINQ for JavaScript
var queryResult2 = Enumerable.From(jsonArray)
.Where("$.user.id < 200")
.OrderBy("$.user.screen_name")
.Select("$.user.screen_name + ':' + $.text")
.ToArray();
Homepage: http://linqjs.codeplex.com/
Homepage: http://neue.cc/reference.htm
objeq
objeq is a simple library that allows POJSO's (Plain-Old JavaScript Objects) to be queried in real-time.
var res = $objeq(data, "age > 40 && gender == 'female' -> name");
// --> Returns ['Jessica']
Homepage: https://github.com/agilosoftware/objeq
json:select()
CSS-like selectors for JSON.
.lang:val("Bulgarian") ~ .level
Homepage: http://jsonselect.org/#tryit
Javascript Array Filtering from Paul's Programming Pearls
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 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" );
Homepage: http://www.paulfree.com/28/javascript-array-filtering/#more-28
Javascript Array Filtering from Paul's Programming Pearls is currently my favorite - its extremely small footprint and blazing fast result speak for itself.
The idea behind is similar to John Resig's JavaScript Micro-Templating effort - a very simple piece of code transforming a string into a Javascript function utilizing Regexp power.
Yes, sure - there are more powerful solutions in the list. Paul's implementation prototype lacks syntax checking of the filter expression but I am sure you can handle javascript syntax checking by yourself.
At the end you must decide which one is best for your project.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment