in reply to Tidy up json from nulls, empty arrays and hashes

Thank you for your hints.

If $r is a hash ref, then $$r is a hash, then $$r{$k} is a value in that hash. This is of course the matter of style only.

Yes -- I'm doing deep recursion. Example of use below:

# echo '{"alfa": { "beta": null, "teata": null, "adfa": null, "n": {}, + "ixi": {}, "marr": [1, 2] } }' | ./tidyup_json { "alfa" : { "marr" : [ 1, 2 ] } } # echo '{"alfa": { "beta": null, "teata": null, "adfa": null, "n": {}, + "ixi": {}, "marr": [null, null] } }' | ./tidyup_json null # echo '{"alfa": { "beta": null, "teata": null, "adfa": null, "n": {}, + "ixi": {}, "marr": [null, null, 3] } }' | ./tidyup_json { "alfa" : { "marr" : [ 3 ] } } # echo '{"alfa": { "beta": { "gamma" : 3 } } }' | ./tidyup_json { "alfa" : { "beta" : { "gamma" : 3 } } } # echo '{"alfa": { "beta": { "gamma" : {} } } }' | ./tidyup_json null # echo '{"alfa": { "beta": { "gamma" : {} }, "nth": 9 } }' | ./tidyup_ +json { "alfa" : { "nth" : 9 } }

Replies are listed 'Best First'.
Re^2: Tidy up json from nulls, empty arrays and hashes
by choroba (Cardinal) on May 30, 2020 at 11:45 UTC
    > If $r is a hash ref, then $$r is a hash, then $$r{$k} is a value in that hash.

    That's not true, and that's why the syntax is confusing.

    $ perl -Mstrict -we 'my $r = {}; say $$r' Not a SCALAR reference at -e line 1.

    If $r is a hash ref, then %$r is a hash, then $$r{$k} is a value in that hash. Therefore, I prefer the $r->{$k} syntax.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]