-
-
Save M1ke/2188e0fb4d53225a62dc36e455611d47 to your computer and use it in GitHub Desktop.
~/.jq for handy jq pipes
This file contains 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
# https://stackoverflow.com/a/28641626/518703 | |
def decode_ddb: | |
def _sprop($key): select(keys == [$key])[$key]; # single property objects only | |
((objects | { value: _sprop("S") }) # string (from string) | |
// (objects | { value: _sprop("NULL") | null }) # null (from boolean) | |
// (objects | { value: _sprop("B") }) # blob (from string) | |
// (objects | { value: _sprop("N") | tonumber }) # number (from string) | |
// (objects | { value: _sprop("BOOL") }) # boolean (from boolean) | |
// (objects | { value: _sprop("M") | map_values(decode_ddb) }) # map (from object) | |
// (objects | { value: _sprop("L") | map(decode_ddb) }) # list (from encoded array) | |
// (objects | { value: _sprop("SS") }) # string set (from string array) | |
// (objects | { value: _sprop("NS") | map(tonumber) }) # number set (from string array) | |
// (objects | { value: _sprop("BS") }) # blob set (from string array) | |
// (objects | { value: map_values(decode_ddb) }) # all other non-conforming objects | |
// (arrays | { value: map(decode_ddb) }) # all other non-conforming arrays | |
// { value: . }).value # everything else | |
; | |
# https://stackoverflow.com/a/69754759/518703 (also proceed with "| column -ts $'\t'") | |
def pretty_table: | |
(.[0]|keys_unsorted|(.,map(length*"-"))),.[]|map(.)|@tsv | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two tools (so far) for doing nice DDB output on CLI. E.g.