OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 

A completely fair and balanced comparison of php json libraries

By admin (2007-03-04. 2853 views.)
The author provides a detailed comparison of popular JSON methods.

The recent release of php 5.2.0, which includes by default an extension for converting php values from and to the JSON format, is a good occasion for comparing the different existing php libraries which aim to provide the same capabilities.

The JSON homepage lists quite a few php libraries, but only 4 are in fact available for download and look stable and maintained:

  • The lib written originally by Omar Kilani is the one that is now officially part of PHP

  • The JSON lib, orginally written by M. Migurski and now officially part of PEAR

  • The Zend_Json lib, which is part of the Zend Framework

  • The Jsonrpc (and Json) extension to the php-xmlrpc lib (written by yours truly)


The first one is the only library written in C. Its evident advantage in terms of execution speed is (was) accompanied by portability problems that the other three, being written purely in php, do not have.

The second one was (to the best of my knowledge) the first implementation of JSON in PHP. Its inclusion in PEAR is a guarantee of stability and quality of code.

The third one is more recent, but it is backed up by the company behind the PHP engine, and is part of a framework of components that is very fashionable at the moment and will probably see widespread adoption in the future.

The fourth one was built to add support for the json-rpc protocol to an existing xmlrpc implementation, and later expanded to better handle plain json. The json parsing code was originally taken from the Pear lib and incrementally improved.

The comparison revolves around 4 sections: features matrix, code examples, execution speed and encoding/decoding test results.

All comparisons have been carried out on the most recent code available as of the beginning of November 2006 (read: CVS or unstable versions used where available)

The results over a good set of comparisons, including graphs, is available at http://gggeek.altervista.org/sw/article_20061113.html.

...

And the winner is...
Of course there cannot be a winner. Every lib test excels in some aspect and is surpassed in others.

The PHP native JSON extension cannot be beaten for speed, but it is very unforgiving on the json it parses as valid. A sure hit for almost everybody.

The Zend lib is the fastest of the php-based libs, and shows no major drawbacks, excepted for lack of support for php 4 (and a bug in encoding php objects). A solid recommendation for those on shared hosting or in the impossibility to install the extension.

The php-jsonrpc lib is the slowest of the pack at encoding php values (because of its object-centric two step conversion process), but sports more features than any other lib, such as automatic charset conversion or extra support for jsonrpc calls.
It is also the closest to the browsers javascript engines in its json parsing results.

The PEAR lib offers no clear advantage, but it still makes for a valid choice, providing the most forgiving json parser of all.
 

 
   Print this page

Top Sponsor
Symantec\'s Norton SystemWorks 2006
Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting


Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS Free Templates

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005