News for hackers. Stuff that matters.
Re:Pretty-printing JSON and XML on Mac OSX by georgecalm on Sunday November 13, 2011 @06:19PM (#3232110)
Nice! You can set up the following aliases in ~/.zshrc (or ~/.bashrc):

  alias json="python -mjson.tool"
  alias xml="xmllint --format -"
then pipe into them like so:

  echo '{"one": 1}' | json
  echo "<one>1</one>" | xml
Re:Pretty-printing JSON and XML on Mac OSX by pamelafox on Sunday November 13, 2011 @09:10PM (#3232497)
My personal toolkit:

JSONView Chrome Extension: https://chrome.google.com/webstore/detail/chklaanhfefbnpoihc...

XML Tree Chrome Extension: https://chrome.google.com/webstore/detail/gbammbheopgpmaagmc...

And JSONlint.com to copy/paste JSON from wherever: http://jsonlint.com/

Also love that Chrome dev tools now pretty prints JSON returned from XHRs in the network response tab.

Re:Pretty-printing JSON and XML on Mac OSX by Groxx on Sunday November 13, 2011 @03:56PM (#3231807)
You could also just pipe it back into the clipboard with | pbcopy :)

A neat set of tricks, hopefully they'll replace jsonlint.com in my brain, and soon :)

Re:Pretty-printing JSON and XML on Mac OSX by ConstantineXVI on Sunday November 13, 2011 @04:12PM (#3231843)
pbcopy/pbpaste are handy enough to point out on their own merit. Handy little timesavers.
Re:Pretty-printing JSON and XML on Mac OSX by _djo_ on Sunday November 13, 2011 @03:45PM (#3231786)
Just be aware that xmllint cleans up XML as well as formatting it, which can in rare circumstances cause some confusion.

So if the incoming XML had an empty tag specified as <tag></tag> xmllint will turn it into <tag/>. If you're specifically looking for <tag></tag> for some reason, then that could trip you up.

Shouldn't matter 99% of the time though.

Re:Pretty-printing JSON and XML on Mac OSX by npollock on Sunday November 13, 2011 @05:25PM (#3231996)
IMO, the best way to spend $50 is on a Charles license - http://www.charlesproxy.com/

It's saved me countless hours debugging web services, be it JSON, XML, AMF, you name it. There's a free 30 day trial, and it runs on Mac OSX, Windows, and Linux.

Re:Pretty-printing JSON and XML on Mac OSX by xerxes2001 on Sunday November 13, 2011 @01:40PM (#3231426)
Hey! Why not use https://github.com/nicksieger/jsonpretty for pretty printing JSON?
Re:Pretty-printing JSON and XML on Mac OSX by georgebashi on Sunday November 13, 2011 @01:46PM (#3231438)
Because these work out-of-the-box on an installation of Snow Leopard or Lion - or in fact, any machine with python 2.6 and/or libxml2, which includes the latest Ubuntu LTS release.

There's definitely better tools out there if you're willing to install something - but these are great when you're in a pinch.

Re:Pretty-printing JSON and XML on Mac OSX by forgotusername on Sunday November 13, 2011 @02:17PM (#3231508)
`tidy` also comes out of the box on OS X. It handles HTML too.

    tidy -xml -q -i < in.xml | less
etc.
Re:Pretty-printing JSON and XML on Mac OSX by jgavris on Sunday November 13, 2011 @07:01PM (#3232199)
I like the jsonview firefox plugin :)