How to print jq output sequentially

天涯浪子 提交于 2020-08-03 14:26:02

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/34839073/how-to-print-jq-output-sequentially

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!