Created
July 25, 2025 01:06
-
-
Save dr-kd/5ca74ba3ca62cb10ec0dcf6f9065d376 to your computer and use it in GitHub Desktop.
JQ invocation to expand all JSON strings, and change any "None" value to delete the key.
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
jq -c 'def try_parse_json: try (fromjson) catch .; | |
def expand_json_strings: walk(if type == "string" then try_parse_json | if type == "string" then . else expand_json_strings end else . end); | |
def remove_none_values: if type == "object" then with_entries(select(.value != "None")) elif type == "array" then map(remove_none_values) else . end$ | |
expand_json_strings | remove_none_values | |
| .[]' | |
# line 2 - anything that expands with fromjson gets expanded | |
# line 3 - any key with the value of "None", the key gets deleted. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment