walles/moar

json is not syntax highlighted when piped in from jq

Closed this issue · 3 comments

json is not syntax highlighted when piped in from jq

There are three(ish) ways to handle this:

  • jq < hello.json | moar --lang=json will tell moar the input is JSON, and moar will highlight it.
  • jq --color-output < hello.json | moar will tell jq to send colored output to moar.
  • moar hello.json will tell moar the input is JSON (based on the .json extension) and moar will highlight it.

The root cause is that jq sends an untyped non-highlighted stream to moar, so moar doesn't know the input is JSON, and can't highlight it.

Note that when you do just jq < hello.json, jq will color its output because it's going to a terminal.

But if you do jq < hello.json | cat, jq will not color its output, because it's going to a stream.

Does this answer your question?

Yes thanks

I suppose you don't want to have a feature for moar to automatically check various common syntaxes for highlighting?

Thinking about it, it should be possible to have moar check for JSON specifically using Go's standard JSON library.

Thanks for the inspiration, let me ponder this.