Monday, February 6, 2017

Pretty Print JSON and XML from Mac OS Command Line

JSON


Must have Python 2.6 or higher version installed.

From Clipboard


After copying unformatted JSON to clipboard (ctrl+c), run this:

pbpaste | python -m json.tool

From File


After saving unformatted JSON to a file called, for example, ugly.json, run this to write it to a file called pretty.json:

cat ugly.json | python -m json.tool > pretty.json

XML


From Clipboard


After copying unformatted XML to clipboard (ctrl+c), run this:

pbpaste | xmllint --format -

pbpaste | xmllint --format -

From File


After saving unformatted XML to a file called, for example, ugly.xml, run this to write it to a file called pretty.xml:

cat ugly.xml | xmllint --format -o pretty.xml -


Set Cmder (ConEmu) console emulator to open new tab in current directory with Bash shell

Windows is a truly bad operating system for almost everything except games. Unfortunately sometimes we have to use it for web development. I...