json-pipe-cli

0.0.1 • Public • Published

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|--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.

Installation

Install globally with npm:

npm install -g json-pipe-cli

Or add to your project as a dependency:

npm install --save json-pipe-cli

CLI Usage

Basic JSON parsing

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 }

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 bar

Output:

Parsed JSON value for json["foo"]["bar"]:
------------------------------------------------
123

Help 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 application

Exit 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

Readme

Keywords

none

Package Sidebar

Install

npm i json-pipe-cli

Weekly Downloads

64

Version

0.0.1

License

none

Unpacked Size

5.98 kB

Total Files

9

Last publish

Collaborators

  • sleep-written