Last active
June 14, 2020 07:26
-
-
Save lamchau/3f9fafdd96f5ca569451539c1d2f93b9 to your computer and use it in GitHub Desktop.
removing null/empty values from JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from: https://github.com/stedolan/jq/issues/104 | |
# more explicit (per value) | |
walk( | |
if type == "object" then | |
with_entries( | |
select( | |
.value != null and | |
.value != "" and | |
.value != [] and | |
.value != {} | |
) | |
) | |
else . | |
end | |
) | |
# faster (marginally) | |
delpaths([path(..?) as $p | select(getpath($p) == null or getpath($p) == [] or getpath($p) == {}) | $p]) | |
# usage | |
jq 'delpaths([path(..?) as $p | select(getpath($p) == null or getpath($p) == [] or getpath($p) == {}) | $p])' <filename.txt> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment