

PJSON: pretty, colorful json output formatting for terminal - auston
http://igorgue.com/pjson/

======
geofft
If this is based on pygments, is it reasonable to have a command like this
that works on everything pygments knows how to highlight, and plugs into a
bunch of pretty-printers / reformatters, e.g. GNU indent?

Is there an equivalent of pygments for pretty-printing all the things?

~~~
StavrosK
Yes, it's the "pygmentize" command, included in pygments. Also, pygments is a
fantastic tool, I love it.

------
nigma
Here's a similar trick with the Python json module:

    
    
      echo '{"hello":"there"}' | python -mjson.tool

~~~
oylenshpeegul
And Perl's JSON::XS

    
    
         echo '{"hello":"there"}' | json_xs

~~~
oylenshpeegul
Or for pretty colors, try Data::Printer

    
    
        echo '{"hello":"there"}' | perl -MJSON -MDDP -E '$f = decode_json readline; p $f'

~~~
harbud
Is there a colored JSON dumper in Perl?

------
maratd
Wait wait ... what are the unicode characters for that cloud and lightning
bolt? That looks awesome.

~~~
igorgue
Author here, unfortunately no thunder on Mountain Lion :( [1]

It's from my zsh theme: [https://raw.github.com/igorgue/oh-my-
zsh/master/themes/igorg...](https://raw.github.com/igorgue/oh-my-
zsh/master/themes/igorgue.zsh-theme) I stole it from the cloud theme and
another theme that I don't remember.

The thunder lights up when the program doesn't end property (return 0).

[1] <3 thunder <http://wiki.xkcd.com/irc/Heart_Thunder>

~~~
ZoFreX
> The thunder lights up when the program doesn't end property (return 0).

Inspired! Did you come up with that part?

~~~
igorgue
Haha yes.

This is the code add it at the end of your prompt:

    
    
        function thunder() {
            echo "%(?,%{$fg_bold[grey]%}⚡%{$reset_color%},%{$fg_bold[yellow]%}⚡%{$reset_color%})"
        }

------
axiak
Why all of that complicated setup? Why not just support pip install pjson? :)

~~~
xster
agreed, needs to be submitted to pypi now!

------
RealCasually
We recently discussed underscore-cli here on Hacker News
(<http://news.ycombinator.com/item?id=4491058>) and I find it to offer more
than this, but still a nice tool.

<https://github.com/ddopson/underscore-cli>

------
petepete
This looks really good, thanks.

Rather than pipe curl's output through stuff though, for the most part I use
httpie [1]. It's a human-friendly curl wrapper.

[1] <https://github.com/jkbr/httpie>

------
void-star
I've been using json_reformat which comes from "yajl" to do this sort of thing
for a while.

EDIT: I love seeing something that does an "awesome-print" with terminal
colorization, though.

------
marksands07
Hey kids, why shouldn't every python tool have a Ruby counterpart? :)
<https://github.com/marksands/pjson-rb>

~~~
zgryw
Come on, you should use coderay instead of pygments. 100% ruby ;)

~~~
marksands07
Sweet! I went with a quick conversion rather than doing any research. Thanks
for the link, I'll definitely give it a whirl tomorrow evening.

------
Anm
"Small retina display images are fucking huge."

Even when reshown on retina displays, since the HTML standard is to attend to
the pixel size and not the physical resolution. Screenshots taken with the
standard Cmd-Shift-4 or similar all include proper resolution metadata, should
someone want to show it at the correct size.

------
michaelmior
alias pjson='pygmentize -l json'

~~~
sciurus
I'm curious how the author managed to learn the pygments library without
learning it already provided a command. This script can be replaced by

alias pjson='pygmentize -l json'

If you're passing it the file name, pygmentize will figure out the lexer to
use, e.g.

pygmentize foo.json

pygmentize bar.rb

It's only when you have it read from stdin that you need to specify, e.g.

pygmentize -l json < foo.json

------
chipaca
Not sure what this offers over what I currently have in ~bin with a similar
name,

python -m json.tool "$@" | pygmentize -l json | less -RSNFX

------
Argorak
For those that want to stay in Ruby land:

$ gem install jazor coderay

$ echo '{"foo": "bar"}' | jazor | coderay -json

------
mazlix
oh man.. I was looking for exactly this earlier today.. it looks REALLY pretty

------
bryanlarsen
many more options here: [http://stackoverflow.com/questions/352098/how-to-
pretty-prin...](http://stackoverflow.com/questions/352098/how-to-pretty-print-
json-script)

~~~
benatkin
This here is my favorite. <http://stackoverflow.com/a/6066102/3461>

------
diegogomes
#cool

