Thursday, February 26th, 2009

JSONView: JSON browser from within Firefox

Category: JSON, Utility

JSONView is a new Firefox extension that gives you a nice way to view your JSON documents (JSONovich also does the trick).

Ben Hollis talks about the extension:

The extension itself is pretty simple. I wasn’t sure how to approach the problem of supporting a new content type for Firefox, so I followed the example of the wmlbrowser extension and implemented a custom nsIStreamConverter. What this means is that I created a new component that tells Firefox “I know how to translate documents of type application/json into HTML”. And that it does – parsing the JSON using the new native JSON support in Firefox 3 (for speed and security) and then constructing an HTML document that it passes along the chain. This seems to work pretty well, though there are some problems – some parts of Firefox forget the original type of the document and treat it as HTML, so “View Page Info” reports “text/html” instead of “application/json”, “Save as…” saves the generated HTML, Firebug sees the generated HTML, etc. Just recently I came across the nsIURLContentListener interface, which might offer a better way of implementing JSONView, but I’m honestly not sure – the Mozilla documentation is pretty sparse and it was hard enough to get as far as I did. I’m hoping some Mozilla gurus can give me some pointers now that it’s out in the open.

Posted by Dion Almaer at 10:31 am

4.1 rating from 17 votes


Comments feed TrackBack URI

Cool. BTW, note that the more recent releases of Firebug have support for inspecting the contents of JSON requests. Or so I’m told, although I’ve been having trouble getting this to work.

Comment by broofa — February 26, 2009

This is a great addition to Firefox…any chance it could handle formatting JSONP responses too by recognizing the callback in the query string?

Comment by ryankuykendall — February 26, 2009

@ryankukendall: Detecting and handling JSONP is super high on my list of things to implement for JSONView. Feel free to vote for it though:

Comment by dalangalma — February 26, 2009

the beta version of FireBug if quite buggy. I did install it for sake of JSON support but had to revert back to older version.

Comment by kadnan — February 28, 2009

Leave a comment

You must be logged in to post a comment.