perl5
perl5 copied to clipboard
Add a new perlrun option "-j" which allows JSON parsing in line
With this option we basically extend the already existing "-n" and "-p" flags to handle JSON using the inbuilt "JSON::PP" module. Basically we decode the STDIN from "$" with decode_json into $ again so you can run something like:
sudo journalctl -f -o json | ./perl -njle 'if ( $_->{"_GID"} == 0 ) {print $_->{"MESSAGE"}}'
To quickly filter out all root processes, this would make adhoc log analysis of most modern applications a more convenient.
I am by no means a Perl expert so this probably needs some adjustment to fit in, I also at this point have no idea where I would stash some tests for this, but it might be worth discussing merit before spending the time testing, the change works well enough for me now that the idea is reviewable.
- This set of changes requires a perldelta entry, and I need help writing it.