Skip to content

Instantly share code, notes, and snippets.

@deas
Created February 18, 2026 14:33
Show Gist options
  • Select an option

  • Save deas/a4c47809bbee6d633e05d938a8b31b2e to your computer and use it in GitHub Desktop.

Select an option

Save deas/a4c47809bbee6d633e05d938a8b31b2e to your computer and use it in GitHub Desktop.
#!/bin/sh
depth=$1
jq 'def scrub(n):
if type == "object" then
if n == 0 then empty
else map_values(scrub(n - 1)) | with_entries(select(.value != null))
end
elif type == "array" then
if n == 0 then empty
else map(scrub(n - 1))
end
else .
end;
scrub('"${depth}"')'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment