Skip to content

Instantly share code, notes, and snippets.

@dr-kd
Created July 25, 2025 01:06
Show Gist options
  • Save dr-kd/5ca74ba3ca62cb10ec0dcf6f9065d376 to your computer and use it in GitHub Desktop.
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.
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