json-pipe-cli
v0.0.1
Published
A simple CLI for reading and parse JSON from stdin
Readme
json-pipe-cli
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.
Features
- Read JSON input from
stdin. - Extract one or more nested properties via
-k|--keysflags. - 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.
Installation
Install globally with npm:
npm install -g json-pipe-cliOr add to your project as a dependency:
npm install --save json-pipe-cliCLI Usage
Basic JSON parsing
Read JSON from a file or other command and pretty-print the entire object:
cat data.json | json-pipe-cliOutput:
Parsed JSON:
------------------------------------------------
{ "foo": { "bar": 123 }, "baz": true }Extract nested keys
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 barOutput:
Parsed JSON value for json["foo"]["bar"]:
------------------------------------------------
123Help on missing pipe
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 applicationExit Codes
| 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 |
