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 |