brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: journalctl -o json-seq writes records that survive a cut off stream

Journalctl
~/tips/tip-journalctl-json-seq

journalctl -t demoapp -n 1 -o json-seq | od -c | head -1

Get JSON records with a clear start marker, so a half written line can be skipped.

-o json writes one object per line, which is fine until a pipe gets cut halfway through a record. json-seq marks the start of every record so a reader can recover.

This mode follows RFC 7464: each object starts with an ASCII record separator byte (0x1E) and ends with a newline. Looking at the raw bytes shows it:

journalctl -t demoapp -n 1 -o json-seq | od -c | head -1

The first character in that dump is 036, the octal code of the separator, followed by the usual {"__SEQNUM_ID":.... jq understands the format with its --seq option:

journalctl -u myapp -f -o json-seq | jq --seq -r .MESSAGE

Where I find it useful is when the output goes to a file that another process reads while it is still being written, or over a flaky network pipe. A truncated record is easy to spot and skip, and the next one starts clean.

For quick one shot queries plain -o json is simpler, because many tools choke on the separator byte. Plain grep or a JSON parser that does not know RFC 7464 will treat it as garbage at the start of each line. The man page lists the mode as added in systemd 240.

Further reading: journalctl man page (output modes), RFC 7464: JSON Text Sequences

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b ls -lh /var/log/journal/*/*.journal~ Storage=volatile sudo journalctl --setup-keys All Journalctl tips (81) All topics

Link