Tag: development / Back

I recently came across the problem of needing to "pretty print" a json output to debug a JSON API call. The only script i came across was a .NET application?!?! anyway, a few lines of python did the trick (i guess 1 line of perl would've done the job, but it doesn't have a standard JSON library)

#!/usr/bin/python

import sys
import json

x = json.load(sys.stdin)
print json.dumps(x, indent = 2)


pretty sophisticated, right? well... 10 minutes of googling solved by 1 minute of coding.. great

usage is obvious i guess...

Herbys-i7:~ herbert$ curl -s \
  "http://xxx/data/admin?cmd=listInactiveUsers&format=djson" \
  | jsontidy
{
  "users": [
    {
      "username": "test5", 
      "id": "d3292a0c-d152-42b1-98d0-335ded789bc6"
    }, 
    {
      "username": "test2", 
      "id": "0d947487-bccc-4742-bf4e-0b0afeb2011f"
    }
  ]
}


Of course you could also do it in one line.. how about using the following in your .bash_profile?

alias jsontidy='python -c "import sys,json;json.dump(json.load(sys.stdin), sys.stdout, indent=2)"'


Hey, we have Signatures !!! Great, isn't it ? ;)

Posted by Herbert Poul

Assigned Tags: development, debug, json

1 Comments
Want to create a list of all things you have read, watched, used or otherwise own - categorized using tags, rated and review them - and obviously share them with your friends?

Then check out ShelfShare. It is a simple application hosted on google app engine which will allow you all that and more - like exporting all your ratings and reviews using a CSV file, or subscribe to the shelves of your friends using RSS feeds.

I would love to receive feedback if this looks useful, or what would make it useful :)

Thanks to gerhard for testing it as a first user :)
Hey, we have Signatures !!! Great, isn't it ? ;)

One year of SCT !

2008-02-23 20:50:44

I just realized that Sphene Community Tools (My currently most active private project implementing a django forum and wiki application) is already one year in development. This finally removes the "Short source control history" - warning on it's Ohloh project page.
Hey, we have Signatures !!! Great, isn't it ? ;)

Posted by Herbert Poul

Assigned Tags: sct, development, django

0 Comments

Simple CRUD application in django

2008-02-10 20:25:34

I've just finished my simple CRUD application in django for my WebappFrameworkComparison - This makes it four frameworks in which i've implemented the simple BarCrud application.
Hey, we have Signatures !!! Great, isn't it ? ;)

Page 1

Archive

RSS Feed

Personal website and blog of Herbert Poul. Also check out my Photo Gallery.




Herby's Photo Gallery

Subscriptions

User

You are not logged in.
Login
Register