-
Notifications
You must be signed in to change notification settings - Fork 0
Home
nntrn edited this page Aug 19, 2023
·
5 revisions
jq -r '(.[0] | keys_unsorted) as $keys | ([$keys] + map([.[ $keys[] ]])) [] | @csv'
jq -R -s 'def objectify(headers): . as $in | reduce range(0; headers|length) as $i ({}; .[headers[$i]] = ($in[$i] | tonumber? // .) ); def csv2table: split("\n") | map( split(",") | map(sub("^ +";"") | sub(" +$";"")) ); def csv2json: csv2table | (.[0]|map(gsub(" "; "_")|gsub("[()]";""))) as $headers | reduce ( .[1:][] | select(length > 0) ) as $row ( []; . + [ $row| objectify($headers) ]); csv2json'
JOIN_KEY=...
jq --arg joinkey $JOIN_KEY 'JOIN(INDEX(inputs[];.[$joinkey]);.[];.[$joinkey];add)'
DELETE_KEY=...
jq --arg deletekey $DELETE_KEY 'walk(if type == "object" then . | del(.[$deletekey]) else . end)'
GROUPBY_KEY=...
jq --arg groupbykey $GROUPBY_KEY '{"\($groupbykey)": group_by(.[$groupbykey]) | map({"\(.[0][$groupbykey])": length}) | add}'
jq 'def summary($item): {"\($item)":group_by(.[$item])|map({"\(.[0][$item])":length})|add}; [(.[0]|keys)[] as $keys | summary($keys)] | add'
jq 'map(. as $in | reduce leaf_paths as $path ({}; . + { ($path | map(tostring) | join(".")): $in | getpath($path) }))'
gsub("[^a-zA-Z0-9]"; "_")
gsub(" "; "_")
For object
jq 'to_entries|map({key:(.key|gsub(" "; "_")),value})|from_entries'
For array of objects:
jq 'map(to_entries|map({key:(.key|split(" (")[0]|gsub("[^a-zA-Z0-9]"; "_")|ascii_downcase),value})|from_entries)'
jq -n 'env'
Remove user from gist comments:
curl -s https://api.github.com/gists/ee26cb2a0716de0947a0a4e9a157bc1c/comments |
jq 'walk(if type == "object" then . | del(.user) else . end)'