News for hackers. Stuff that matters.
Re:PJSON: pretty, colorful json output formatting for terminal by geofft on Tuesday September 18, 2012 @08:11PM (#4541306)
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?

Re:PJSON: pretty, colorful json output formatting for terminal by StavrosK on Wednesday September 19, 2012 @07:13AM (#4543042)
Yes, it's the "pygmentize" command, included in pygments. Also, pygments is a fantastic tool, I love it.
Re:PJSON: pretty, colorful json output formatting for terminal by sciurus on Thursday September 20, 2012 @12:35PM (#4549358)
Re:PJSON: pretty, colorful json output formatting for terminal by nigma on Tuesday September 18, 2012 @08:12PM (#4541311)
Here's a similar trick with the Python json module:

  echo '{"hello":"there"}' | python -mjson.tool
Re:PJSON: pretty, colorful json output formatting for terminal by ericmoritz on Tuesday September 18, 2012 @09:36PM (#4541574)
dang and all this time I've been doing this all this time:

   echo '{"hello": "there"}' | python -c "import json, sys; print json.dumps(json.load(sys.stdin), indent=4)"
Thanks for the tip!
Re:PJSON: pretty, colorful json output formatting for terminal by oylenshpeegul on Tuesday September 18, 2012 @08:34PM (#4541385)
And Perl's JSON::XS

     echo '{"hello":"there"}' | json_xs
Re:PJSON: pretty, colorful json output formatting for terminal by oylenshpeegul on Tuesday September 18, 2012 @08:39PM (#4541402)
Or for pretty colors, try Data::Printer

    echo '{"hello":"there"}' | perl -MJSON -MDDP -E '$f = decode_json readline; p $f'
Re:PJSON: pretty, colorful json output formatting for terminal by harbud on Thursday September 20, 2012 @09:35AM (#4548419)
Is there a colored JSON dumper in Perl?
Re:PJSON: pretty, colorful json output formatting for terminal by lttlrck on Tuesday September 18, 2012 @08:48PM (#4541435)
yeah that's mentioned on the second line of TFA
Re:PJSON: pretty, colorful json output formatting for terminal by maratd on Tuesday September 18, 2012 @07:46PM (#4541202)
Wait wait ... what are the unicode characters for that cloud and lightning bolt? That looks awesome.
Re:PJSON: pretty, colorful json output formatting for terminal by JoshTriplett on Tuesday September 18, 2012 @07:54PM (#4541236)
Thanks to gucharmap's excellent Unicode character search:

☁ U+2601 CLOUD

⚡ U+26A1 HIGH VOLTAGE SIGN

Re:PJSON: pretty, colorful json output formatting for terminal by igorgue on Tuesday September 18, 2012 @08:11PM (#4541308)
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... 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

Re:PJSON: pretty, colorful json output formatting for terminal by ZoFreX on Wednesday September 19, 2012 @08:44AM (#4543261)
> The thunder lights up when the program doesn't end property (return 0).

Inspired! Did you come up with that part?

Re:PJSON: pretty, colorful json output formatting for terminal by igorgue on Wednesday September 19, 2012 @03:12PM (#4545032)
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%})"
    }
Re:PJSON: pretty, colorful json output formatting for terminal by zokier on Wednesday September 19, 2012 @04:08AM (#4542643)
There is unicode characters (code points, graphemes, whatevs) for everything

http://unicodesnowmanforyou.com/

Re:PJSON: pretty, colorful json output formatting for terminal by mburns on Tuesday September 18, 2012 @07:54PM (#4541238)
Re:PJSON: pretty, colorful json output formatting for terminal by axiak on Tuesday September 18, 2012 @10:25PM (#4541700)
Why all of that complicated setup? Why not just support pip install pjson? :)
Re:PJSON: pretty, colorful json output formatting for terminal by xster on Thursday September 20, 2012 @01:25PM (#4549600)
agreed, needs to be submitted to pypi now!
Re:PJSON: pretty, colorful json output formatting for terminal by RealCasually on Tuesday September 18, 2012 @09:49PM (#4541609)
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

Re:PJSON: pretty, colorful json output formatting for terminal by petepete on Wednesday September 19, 2012 @03:31AM (#4542546)
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

Re:PJSON: pretty, colorful json output formatting for terminal by void-star on Tuesday September 18, 2012 @11:25PM (#4541891)
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.

Re:PJSON: pretty, colorful json output formatting for terminal by marksands07 on Wednesday September 19, 2012 @01:28AM (#4542264)
Hey kids, why shouldn't every python tool have a Ruby counterpart? :) https://github.com/marksands/pjson-rb
Re:PJSON: pretty, colorful json output formatting for terminal by zgryw on Wednesday September 19, 2012 @03:05AM (#4542485)
Come on, you should use coderay instead of pygments. 100% ruby ;)
Re:PJSON: pretty, colorful json output formatting for terminal by marksands07 on Wednesday September 19, 2012 @03:50AM (#4542600)
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.
Re:PJSON: pretty, colorful json output formatting for terminal by igorgue on Wednesday September 19, 2012 @02:12AM (#4542362)
This is awesome :)
Re:PJSON: pretty, colorful json output formatting for terminal by Anm on Tuesday September 18, 2012 @10:31PM (#4541717)
"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.

Re:PJSON: pretty, colorful json output formatting for terminal by michaelmior on Tuesday September 18, 2012 @09:44PM (#4541597)
alias pjson='pygmentize -l json'
Re:PJSON: pretty, colorful json output formatting for terminal by sciurus on Thursday September 20, 2012 @12:33PM (#4549347)
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

Re:PJSON: pretty, colorful json output formatting for terminal by chipaca on Wednesday September 19, 2012 @05:49AM (#4542872)
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

Re:PJSON: pretty, colorful json output formatting for terminal by Argorak on Wednesday September 19, 2012 @03:57AM (#4542617)
For those that want to stay in Ruby land:

$ gem install jazor coderay

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

Re:PJSON: pretty, colorful json output formatting for terminal by mazlix on Wednesday September 19, 2012 @06:09AM (#4542910)
oh man.. I was looking for exactly this earlier today.. it looks REALLY pretty
Re:PJSON: pretty, colorful json output formatting for terminal by bryanlarsen on Tuesday September 18, 2012 @09:19PM (#4541531)
Re:PJSON: pretty, colorful json output formatting for terminal by benatkin on Tuesday September 18, 2012 @11:58PM (#4541981)
This here is my favorite. http://stackoverflow.com/a/6066102/3461
Re:PJSON: pretty, colorful json output formatting for terminal by diegogomes on Tuesday September 18, 2012 @07:35PM (#4541165)
#cool