Computer Beacon high quality .NET libraries in open source

JSON Toolkit 4.0

Posted on 6/19/2012

JSON Toolkit 4.0 further improves the performance of JSON Toolkit and supports more platforms like Windows Phone and Windows 8.

You may download the library at either CodePlex or NuGet.

The new library is not compatible to Facebook Graph Toolkit yet, because it involves a namespace change. It will be integrated with FGT 4.0, which will bring support to ASP.NET MVC, Silverlight, Windows Phone, Windows 8, Open Graph, Facebook Page Administration and more.

It's very fast

To give you an idea how fast JSON Toolkit 4.0 is, the graphs below show the time taken to parse different JSON data. The sample data used in the test are:

OP Feed: The posts on the Facebook Page of Ocean Park Hong Kong, obtained at https://graph.facebook.com/hkoceanpark/posts
CB Feed: The posts on the Facebook Page of Computer Beacon, obtained at https://graph.facebook.com/computerbeacon/posts
Java Servlet: data of Servlets
Bing: A sample response from the Bing Api

All graphs measure the time taken to repeat the operation 5000 times. Smaller values are better.

Improvement in 4.0

The graph below illustrates the difference in parsing performance of Version 4.0 against Version 3.1.

JSON Toolkit 4.0 vs 3.1

Parse performance

JSON Toolkit is one of the fastest .NET libraries for managing JSON strings and objects. To illustrate this, three different libraries are brought together for comparison:

JavaScriptSerializer 4.0.0.0: A built-in class of .NET, found at System.Web.Script.Serialization namespace
Json.NET 4.5.0.0
Jayrock 0.9.12915.0

The tests are conducted by parsing a JSON string into a JSON object instance or Dictionary<string,object> instance. The time is measured by repeating the tests 5000 times. Here are the results:

Time to parse JSON strings
Time to parse a sample JSON string 5000 times. Smaller values are better.

As we can see, JSON Toolkit takes much less time to parse JSON objects, particularly those from Facebook. When an application using Facebook Graph Toolkit is deployed to the server, JSON Toolkit will save your server resources!

Stringify performance

JSON Toolkit also offers the ability to "stringify" a JsonObject or JsonArray, i.e. given an instance in memory, turn that object into a string which can be stored or transmitted and then converted back to JsonObject or JsonArray instance later.

The chart below compares the performance of different libraries in performing the equipvalent of "stringify" operation:

Time to stringify JSON objects
Time to strinfigy JSON objects 5000 times. Smaller values are better.

Test environment

The above tests are conducted under the following environment:

Hardware: Intel E8400, 8GB DDR2-1066 RAM

Software: Windows 7 x64 SP1

Test project: .NET 4.0, x86 Release build

Support for more platforms

JSON Toolkit is now compiled to a portable class library. This dll can be used in Silverlight, Windows Phone, XNA games and also Windows 8. As a side note, it is used in one of my recent Windows Phone applications to persist data between app launches :->

Upcoming features

You may notice that the deserialize<T> method has been removed in this release. The reason is that JSON Toolkit was originally designed to support Facebook Graph Toolkit only by handling parse operations. During development of version 4.0 it was decided that the whole serialize and deserialize algorithms have to be rewritten to achieve maximum performance. To avoid delaying FGT, the deserialize method is temporarily removed and will be added back later.


Next: Debug Facebook Applications in Visual Studio using SSL Previous: FGT Update v3.1

Comments

Add comment
Name:
Comment: