Xiphias
Xiphias

Reputation: 4716

How to print jq output sequentially

When using jq to process JSON, I often lose the overview due to long JSON objects. Thus, something like jq . | less would be nice. However, although the above works, the nice coloring by jq is gone.

Is there another way to read jq's output line by line, or window by window, without having the terminal spammed with the full JSON object?

Edit: This did not work for me: echo '{"hello": "world"}' | jq . | less -C

Upvotes: 26

Views: 8398

Answers (2)

peak
peak

Reputation: 116880

Use the jq -C (colorize) option before paginating it with a pager like more -r or less -r.

Upvotes: 33

Alfred
Alfred

Reputation: 61793

report.json is a file with JSON (cat report.json prints but not formatted)

cat report.json | jq . -C | more

Outputs jq with pager and color

or via less instead of more

cat report.json | jq . -C | less -r

P.S: the comments in this question where also helpful so thanks for that

Upvotes: 18

Related Questions