Skip to content

Instantly share code, notes, and snippets.

@fabienhinault
Last active May 22, 2025 15:10
Show Gist options
  • Save fabienhinault/e52f12804e65de05ec96a181ff8a5966 to your computer and use it in GitHub Desktop.
Save fabienhinault/e52f12804e65de05ec96a181ff8a5966 to your computer and use it in GitHub Desktop.
# https://github.com/stedolan/jq/blob/master/src/builtin.jq
# https://github.com/stedolan/jq/blob/ca12bd9b5d15c0c4e5bd01d706ddbb3f4edefd36/src/builtin.jq
# Apply f to composite entities recursively, and to atoms
def walk(f):
. as $in
| if type == "object" then
reduce keys_unsorted[] as $key
( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f
elif type == "array" then map( walk(f) ) | f
else f
end;
def toDate1000: . / 1000 | todate;
def showDates: walk(if (type == "number" and . > 1000000000000) then tostring + " " + toDate1000 else . end);
#https://stackoverflow.com/questions/74195390/jq-library-overriding-existing-keys-of-an-json-object-with-another-object-keys#answer-74197668
def merge($source):
. as $target
| reduce ($source | keys | map(select(in($target))))[] as $key ($target;
.[$key] = if (.[$key] | type) == "object"
then .[$key] | merge($source[$key])
else $source[$key]
end
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment