[Bend-pm] JSON pretty printing

Josh Lavin pm at jlavin.com
Mon Aug 22 14:48:55 PDT 2016


On Mon, Aug 22, 2016, at 11:20 AM, Tim Howe wrote:
> I seem to recall a question about pretty printing JSON when we last
> met, and I had said I had done this.  Apparently I used this:
> https://metacpan.org/pod/JSON
> 
> 	I have a simple example in my Catalyst version of PieNg:
> https://github.com/thowe/PieNg/blob/master/lib/PieNg/Controller/Logs.pm#L47

Nice, thanks!

I got curious and tried to cook up my own little script to use to pass
in JSON and pretty-print it back, used like:

echo '{"subtotal":21.40,"quantity":2,"description":"Foo"}' | js

It worked great, but then I wanted colorized output. I found an existing
CPAN module, App::lj (https://metacpan.org/pod/App::LJ) which provides
an `lj` script to do that same thing.

It uses JSON::Color. However, JSON::Color won't keep integers, but
instead makes them strings. :-( I filed a bug.

Maybe I'll write my own colorization. For now, here's my script:
https://gist.github.com/jdigory/78751834e71291103d7d39bdd1bb48bc

Josh


More information about the Bend-pm mailing list