Blog archives

JSON viewer with URL support (in PHP+jQuery)

Like many other people, i’m quite charmed by the JSON data interchange format as a replacement for the almost ubiquitous XML format. Unfortunately, there are less tools for viewing JSON than there are for XML, which gets a bit annoying if you have large JSON files that you need to view, such as the JSON feeds for Flickr.

There is a useful JSON viewer made for Adobe Air but unfortunately it doesn’t accept URLs (only text), so you need to copy-paste JSON text around to view the output.

So, you might have seen this coming, i made my own JSON viewer. It’s a very simple thing, using only PHP (which has JSON support since 5.2.0) and the fantastic jQuery JavaScript library for some AJAX calls and effects. If you want you can try it yourself.

The source code is released under the open source MIT license and can be downloaded here.

Update (06/10/2008): Some API’s deliver invalid JSON, such as Flickr and Google Suggest, usually because they deliver the JSON as a JavaScript variable, e.g.

JSONResult = ({"foo": "bar"});

I ‘fixed’ this in JSON Viewer v1.1 by stripping out all code before and after the { and [ characters. Unfortunately that takes a little bit of extra code, and we are essentialy fixing things that Google or Yahoo should fix, but because these feeds are so popular we do it anyway.

Update (13/02/2009): Two small usability fixes: the first node of the tree is now always shown and clicking on the url field only deletes the complete field if it is the default url. Get the source here.

Update (05/08/2009): For your and my convenience JSON viewer’s source and downloads are now available via Google Code. For your hacking pleasures you can also download the source using Subversion. I’ve updated the source a little bit, so let’s call this release 1.3.

Update (11/10/2009): Some minor updates, changed the SVN repo and revised the design to make it a little nicer on the eyes. Release 1.5

Add a comment