Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 862
Xiphias Avatar asked Jan 17 '16 13:01

Xiphias


People also ask

What is the output of jq?

jq usually outputs non-ASCII Unicode codepoints as UTF-8, even if the input specified them as escape sequences (like "\u03bc"). Using this option, you can force jq to produce pure ASCII output with every non-ASCII character replaced with the equivalent escape sequence.

Does jq use JSONPath?

jp is a JSON processor for the command line using JSONPath (aka "a simpler jq, and with JSONPath").

What is jq format?

jq is a free open source JSON processor that is flexible and straightforward to use. It allows users to display a JSON file using standard formatting, or to retrieve certain records or attribute-value pairs from it.


2 Answers

Use the jq -C (colorize) option, with more -r or less -r.

like image 111
peak Avatar answered Oct 12 '22 14:10

peak


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

like image 30
Alfred Avatar answered Oct 12 '22 14:10

Alfred