-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.jq
29 lines (28 loc) · 1.38 KB
/
.jq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def decode_ddb:
def _prop($key): select(has($key))[$key];
((objects | { value: _prop("S") }) # string (from string)
// (objects | { value: _prop("B") }) # blob (from string)
// (objects | { value: _prop("N") | tonumber }) # number (from string)
// (objects | { value: _prop("BOOL") }) # boolean (from boolean)
// (objects | { value: _prop("M") | map_values(decode_ddb) }) # map (from object)
// (objects | { value: _prop("L") | map(decode_ddb) }) # list (from encoded array)
// (objects | { value: _prop("SS") }) # string set (from string array)
// (objects | { value: _prop("NS") | map(tonumber) }) # number set (from string array)
// (objects | { value: _prop("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
;
def tocsv($x):
$x
|(map(keys)
|add
|unique
|sort
) as $cols
|map(. as $row
|$cols
|map($row[.]|tostring)
) as $rows
|$cols,$rows[]
| @csv;