Tag: json / Back
jsontidy - Pretty printing JSON data
2010-07-08 11:01:01
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)
pretty sophisticated, right? well... 10 minutes of googling solved by 1 minute of coding.. great
usage is obvious i guess...
Of course you could also do it in one line.. how about using the following in your .bash_profile?
#!/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
1 CommentsPage 1
Archive
- December, 2009 1 posts.
- December, 2008 2 posts.
- November, 2009 1 posts.
- November, 2008 1 posts.
- October, 2010 1 posts.
- September, 2008 2 posts.
- August, 2018 2 posts.
- August, 2008 2 posts.
- July, 2018 1 posts.
- July, 2011 2 posts.
- July, 2010 1 posts.
- July, 2009 1 posts.
- July, 2008 1 posts.
- June, 2010 1 posts.
- June, 2009 1 posts.
- May, 2011 1 posts.
- May, 2009 1 posts.
- April, 2011 1 posts.
- April, 2008 1 posts.
- March, 2010 1 posts.
- March, 2009 1 posts.
- February, 2013 1 posts.
- February, 2010 1 posts.
- February, 2009 5 posts.
- February, 2008 3 posts.
- January, 2011 1 posts.
- January, 2010 1 posts.
- January, 2009 4 posts.
- January, 2008 2 posts.