json-pipe-cli
is a simple CLI for reading JSON from stdin, extracting nested keys, and printing the result to stdout. It supports robust error handling for empty pipes or unexpected TTY usage.
- Read JSON input from
stdin
. - Extract one or more nested properties via
-k|--keys
flags. - Clear error messages and distinct exit codes:
- 666: TTY input is not allowed (no pipe provided).
- 999: Pipe provided but no data received (empty input).
- 111: Other runtime or parsing errors.
Install globally with npm:
npm install -g json-pipe-cli
Or add to your project as a dependency:
npm install --save json-pipe-cli
Read JSON from a file or other command and pretty-print the entire object:
cat data.json | json-pipe-cli
Output:
Parsed JSON:
------------------------------------------------
{ "foo": { "bar": 123 }, "baz": true }
Use -k
or --keys
followed by one or more property names to drill into the object:
echo '{"foo":{"bar":123}}' | json-pipe-cli -k foo bar
Output:
Parsed JSON value for json["foo"]["bar"]:
------------------------------------------------
123
If you run json-pipe-cli
without piping data, it will exit with code 666 and display a helpful message:
$ json-pipe-cli
ERROR:
------------------------------------------------
TTY mode isn't allowed for this application
Code | Condition |
---|---|
0 | Successful parsing and output |
666 | No pipe provided (TTY input not allowed) |
999 | Pipe provided but received no data |
111 | JSON parsing error or other runtime failure |