-
Notifications
You must be signed in to change notification settings - Fork 0
/
jq
43 lines (29 loc) · 1.2 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Working with jquery
values=`curl -s $api | jq --raw-output '.items[0]| .volumeInfo.title,.volumeInfo.authors[0]'`
# Parse json from trello export
cat KxP0n8CI.json | jq -r '.cards[].name'
# raw ouput
--raw-output
# access variable in the base level
jq .access_token
# access recursively
jq '.. | .url? '
# multiple search patterns
jq -r '.url,.title'
# multiple search patterns appearing on same line
jq -r '"\(.url), \(.title)"'
# it might suffice to use the following line along with awk getline if you get grep -F to work in awk's grep
#title="$(jq -r '" \(.title)"' ~/data/ytwl.json | sed '/\[Private/d' | sed '/\[Deleted/d' | dmenu -l 30 -fn 'Comic Mono :size=13')"
# remove entries where field is empty and show corresponding id
jq 'del(..| select(.annotations? == []))| .. | .id?'
# select the level of nesting
#Combining the del function with the .[]? array/object value iterator to delete any key/value nested at the fourth level
jq 'del(.[]? | .[]? | .[]? | .[]?)'
# counting top level items
jq ' . | length'
# to open up group of values inside []
jq '.[]'
# selecting multiple level keys
jq ' .data | .[]' | jq '"\( .text), \(.history | .[] | .scoredUp)"'
# return ouput in different format
@csv