bat icon indicating copy to clipboard operation
bat copied to clipboard

Not possible to specify jsonl (JSON lines) in the language parameter

Open aliok opened this issue 1 year ago • 2 comments

I follow logs of a Kubernetes pod. Those logs are in jsonl format (https://jsonlines.org/), where each line is a valid and complete JSON entry.

I see jsonl support is added here: https://github.com/sharkdp/bat/pull/2539. However, it only uses jsonl format if a file name ends with .jsonl. In my case, I use a pipe like

kubectl logs -n my-pod --follow | bat --paging=never -l jsonl

which doesn't work: [bat error]: unknown syntax: 'jsonl'

Is it possible to add a separate language entry for jsonl?

aliok avatar Jul 25 '24 09:07 aliok

Currently the .jsonl files are mapped to the JSON syntax so you should be able to just use -l json.

keith-hall avatar Jul 25 '24 17:07 keith-hall

But in case of a pipe, the tool won't understand that the input is jsonl and not json, hence not doing the syntax highlighting properly.

aliok avatar Jul 26 '24 08:07 aliok

Think this was a misunderstanding—Keith was saying to pass -l json, not -l jsonl (which errors as shown in the issue description).

But in case of a pipe, the tool won't understand that the input is jsonl and not json, hence not doing the syntax highlighting properly.

The original issue was about passing -l jsonl as a flag (which doesn't exist), not about bat inferring file types. Keith wasn't suggesting bat auto-detects format over pipes, that's not a feature bat has.

Since -l json works for jsonl content, think this can be closed.

lmmx avatar Oct 19 '25 21:10 lmmx

In general, bat can try to guess formats from the first line. There is currently no separate syntax highlighting for json vs jsonl, both are highlighted fine with the json syntax definition

keith-hall avatar Oct 20 '25 18:10 keith-hall