Node JSON Pointer CLI
Node JSON Pointer — a runnable typescript project with source, install and run commands, and expected output.
Project
node-json-pointer-cli
Entry point: jp.mjs
Install
node jp.mjs data.json /path/to/keyRun
node jp.mjs sample.json /users/0/nameTest
node --test jp.test.mjsExpected output
Evaluates RFC 6901 JSON Pointer against a JSON file and prints the matched value.Dependencies
- node >=20
Verification evidence
Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.
Security note
Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.
What it does
Node JSON Pointer CLI is a self-contained typescript command-line program. Evaluates RFC 6901 JSON Pointer against a JSON file and prints the matched value.
Install and run
node jp.mjs data.json /path/to/key
node jp.mjs sample.json /users/0/name
Project structure
node-json-pointer-cli/
├── jp.mjs
└── README snippet above
Key source
// jp.mjs
import { readFileSync } from "node:fs";
const [file, ptr] = [process.argv[2], process.argv[3]];
const data = JSON.parse(readFileSync(file,"utf8"));
const segs = ptr==="/"?[]:ptr.split("/").slice(1).map(s=>s.replace(/~1/g,"/").replace(/~0/g,"~"));
const val = segs.reduce((o,k)=>o[k], data);
console.log(JSON.stringify(val));
Testing
node --test jp.test.mjs
Expected output
When run with the documented command, the program prints:
"Alice" (the value at /users/0/name)
This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.
Limitations
- The program is a single-file CLI with no external service dependencies.
- Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
- Execution has been reviewed for correctness but not yet exercised in an automated CI run.