There must be a better way of viewing pretty-printed JSON from Firefox than this. (EDIT: Hail, JSONovich!)

#!/usr/bin/env python
# ~/bin/ 
# Take some JSON from a file or stdin, format it, output to a tempfile, 
# open in EDITOR

from __future__ import with_statement
import os
import sys
import simplejson
import tempfile

EDITOR = "/usr/bin/gedit"

if __name__ == "__main__":
    if len(sys.argv) == 2:
        # if invoked as {FILE}
        json = open(sys.argv[1])
        # if JSON is piped in (e.g., from Firefox, 
        # or cat {FILE} |
        json = sys.stdin
    json = simplejson.load(json)
    # the with_statement is kind of gratuitous but I like it
    with open(tempfile.mktemp('.json'), 'w') as jsonfile:
        simplejson.dump(json, jsonfile, indent=4)
    # all of that and gedit doesn't even highlight JSON
    # I have emacs highlighting JSON but this generates a "stdin is not 
    # a tty" error, so EDITOR is not set to emacs
    # xemacs works a little better, but I need to click:
    # "Options > Syntax Highlighting > In this buffer" every time, despite 
    # saving to custom.el, so EDITOR is not set to xemacs
    # Very annoying!
    os.system("%s %s" % (EDITOR,
And then I set ~/bin/ as the action for application/json in Edit Preferences Applications.

Yuck. Help?