Menu

1 / 2

jq chokes on real-world log streams. So I built a tiny tool that doesn't.

DEV Community·benjamin·5 months ago
#CHIR8Rgj
#dev#json#level#logtidy#photo
Reading 0:00
15s threshold

If you've ever piped a dev server's output into jq to make the JSON logs

readable, you know this dance:

npm run dev | jq

Enter fullscreen mode

Exit fullscreen mode

{ "level" : 30 , "msg" : "server started" , ... } jq: error (at <stdin>: 0 ): Cannot index string with "level"

Enter fullscreen mode

Exit fullscreen mode

It worked for exactly three lines — until your app printed a startup banner, or a

plain console.log , or a stack trace. jq hit one line that wasn't valid JSON

and aborted the entire stream . Now you're back to reading raw JSON with your

eyeballs.

The thing is, real log output is never pure JSON. It's a mix: structured lines

from your logger (pino, winston, structlog, zap…), plus framework noise, plus

whatever you print() -debugged at 2am.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.