Using Python to Format Json

I have been working quite a bit with Json. Json disregards whitespace by implementation this makes the standard format of Json being a single very long line of not so readable text.
Simple example.
{"query":"some text","results":[{"title":"some result","id":"213"}]}
I had some plan to write some simple python script to format it nicely. I have used the json module before, I wasn’t aware it had a format function as part ofjson.tool.

curl + Json + Python
curl 2> /dev/null | python -mjson.tool

I found that with our redirection the error output to /dev/null i was getting.

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 67 0 67 0 0 76 0 –:–:– –:–:– –:–:– 0

Formated Json

    "query": "some text", 
    "results": [
            "id": "213", 
            "title": "some result"

Tags: , ,

Tuesday, July 14th, 2009 Programing Comments Off on Using Python to Format Json

Re Dumping currently loaded Firefox URLs

bryce posted his Perl version of Dumping currently loaded Firefox URLs.

I decided perl is unreadable 🙂 and the file is json any way. So with the python-json package You can get some pretty readable code so I wrote a pretty simple Python version ff-pages.

python /path/to/location/sessionstore.js

I am starting off with python so all comments are welcome.

Update 02/06/2009:
python-json isn’t needed.
Seems to only work with firefox3.5

Tags: ,

Thursday, July 2nd, 2009 Programing 7 Comments