Last active
December 4, 2023 13:07
-
-
Save SchumacherFM/dd522df72c75e461dff0ca7e9725d2e5 to your computer and use it in GitHub Desktop.
Remove all empty values from a JSON file with CLI program jq
This file contains 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
# removes all null, false, "", 0, [], {} and "0001-01-01T00:00:00Z values from a json | |
# files and writes the data back to the original file via program sponge (brew install moreutils jq) | |
# date time string because of GoLang empty time encoding 🙈 | |
jsonRemoveEmpty() { | |
for file in *.json; do | |
cat "$file" | jq 'walk( if type == "object" then with_entries(select(.value != null and .value != false and .value != "" and .value != 0 and .value != [] and .value != {} and .value != "0001-01-01T00:00:00Z") ) else . end)' | sponge "$file" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment