format-json-output
v1.0.3
Published
CLI tool to format JSON lines in output and pass through non-JSON lines
Readme
format-json-output
A simple CLI tool that filters and pretty-prints JSON lines from stdout while passing through any non-JSON lines as-is.
Use Case
Useful for formatting mixed stdout output from processes like npm run start:watch where JSON lines are mixed with logs or other messages.
Installation
npm install -g format-json-outputUsage
npm run start:watch | format-json-outputBehavior
- Lines containing valid JSON objects (enclosed in
{}) are formatted usingJSON.stringify(obj, null, 2). - Lines without JSON or with invalid JSON are output unchanged.
Example
Input:
INFO Starting dev server...
{"event":"build","status":"success"}
WARN Watch mode enabled.Output:
INFO Starting dev server...
{
"event": "build",
"status": "success"
}
WARN Watch mode enabled.