To manipulate JSON data with perl-oneliner I have been writing like this:
% perl -MJSON -0 -E 'say decode_json(<>)->{foo}' data.json
... which tires my fingers. Recently I found ARGV::URL, which may be useful for one-liners, so I wrote the JSON-version of this module, ARGV::JSON.
With this module you can simply use <>
to access the data structure that the JSON represents.
% perl -MARGV::JSON -E 'say <>->{foo}' data.json
Each <>
(readline
) call returns a hashref or something. Like jq with Perl, pretty simple.
Multiple JSONs are returned in order:
% echo '{"x":1}{"x":2}{"x":3}' | perl -MARGV::JSON -n -E 'say $_->{x}' 1 2 3
Now available at GitHub: https://github.com/motemen/perl5-ARGV-JSON