I just spotted Nuba Princigalli's tweet on pretty colorful JSON. Neat!
My first thought was that Perl could do the download without curl
perl -MLWP::Simple -MDDP -MJSON -e 'p decode_json get shift' http://www.reddit.com/r/perl.json
My next thought was that Mojolicious could do the whole thing
perl -Mojo -E 'say r j g(shift)->body' http://www.reddit.com/r/perl.json
The g does the HTTP GET, the j decodes the JSON, and the r dumps it out. But it uses Data::Dumper. How to get it to use Data::Printer instead? I guess we could just use Data::Printer directly
perl -Mojo -MDDP=alias,dump,output,stdout -e 'dump j g(shift)->body' http://www.reddit.com/r/perl.json
Both Mojo and DDP are defining a p, so I'm asking DDP to use dump instead. And DDP uses stderr by default, so I'm asking it to use sdtout instead.
Hrm. Not very satisfying. I feel like I'm fighting both modules. Is there a Data::Printer plugin for Mojolicious that I'm not aware of?
mojo get http://www.reddit.com/r/perl.json | colorify
where colorify is something like this:
https://gist.github.com/3180549
Posted by: Tempire | 07/25/2012 at 11:21 PM
I prefer Nuba Princigalli (or even Tempire, the previous commenter) version for one reason only: UNIX pipes.
By splitting the HTTP request into a separate program, you get a much more useful tool, that can be used not only with HTTP GET output but local files or even clipboard data (use pbpaste or the equivalent for your OS).
Commands that do one thing only and well, and use stdin/stdout to communicate are so much more powerful...
Posted by: www.simplicidade.org | 07/25/2012 at 11:56 PM
curl -s http://www.reddit.com/r/perl.json | perl -MJSON -M'DDP filters=>{-external=>["JSON"]}' -0e 'p decode_json <>'
changes:
* a -0 to handle JSON input with multiple lines
* uses my -- whoa, shameless plug! :) -- just released https://metacpan.org/module/Data::Printer::Filter::JSON :)
Posted by: Nprincigalli | 08/13/2012 at 12:34 PM