jq Flashcards

1
Q

jq (json processor): how to filter out deep level arrays and strings?

A

cat whatever.json | jq ‘.[] | select(.results[].confirmation.dealStatus==”REJECTED”)’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

jq (json processor): how to get the last item in array?

A

[-1]

version 1.5 and above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

jq: how to get unchanged output (identity operator)?

A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

jq: how to get item which has a special char in identifier?

A

cat ordercontainers.json | jq ‘.[-1] | .tim.”$date”’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

jq: how to get sub attribute from object?

A

cat whatever.json | jq ‘.[1] | .result’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

jq: how to merge to json files with objects into a single one?

A

jq -s ‘.[0] * .[1]’ file1 file2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

jq: how to merge to json files with arrays into a single one?

A

jq -s ‘.[0] + .[1]’ file1 file2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly