jsonpath-cli
Advanced tools
+43
| #!/usr/bin/env node | ||
| const jsonpath = require("jsonpath"); | ||
| const args = process.argv.slice(2); | ||
| //TODO validate args | ||
| //TODO add help https://www.npmjs.com/package/jsonpath#jsonpath-syntax | ||
| if (args.length < 1) { | ||
| console.error("missing arg [query string]"); | ||
| process.exit(1); | ||
| } | ||
| const query = (data) => { | ||
| process.stdout.write( | ||
| JSON.stringify(jsonpath.query(JSON.parse(data), args[0]), null, 2) | ||
| ); | ||
| }; | ||
| //Accept input from standard input | ||
| const readStdIn = () => { | ||
| return new Promise((resolve, reject) => { | ||
| const stdin = process.stdin; | ||
| let data = ""; | ||
| stdin.setEncoding("utf8"); | ||
| stdin.on("data", (chunk) => { | ||
| data += chunk; | ||
| }); | ||
| stdin.on("end", () => { | ||
| resolve(data); | ||
| }); | ||
| stdin.on("error", reject); | ||
| }); | ||
| }; | ||
| if (args.length < 1) { | ||
| process.stdout.write({ message: "missing arg" }); | ||
| } else { | ||
| readStdIn().then(query).catch(console.error); | ||
| } |
+0
-0
@@ -0,0 +0,0 @@ MIT License |
+9
-4
| { | ||
| "name": "jsonpath-cli", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Command Line node application to query JSON using jsonpath", | ||
| "main": "bin/jpath-cli.js", | ||
| "main": "bin/index.js", | ||
| "scripts": { | ||
@@ -12,7 +12,12 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
| "bin": { | ||
| "jpath": "bin/jpath-cli.js" | ||
| "jpath": "bin/index.js" | ||
| }, | ||
| "dependencies": { | ||
| "jsonpath": "^1.1.1" | ||
| } | ||
| }, | ||
| "repository": { | ||
| "url": "https://github.com/rsingh25/jsonpath-cli" | ||
| },"keywords": [ | ||
| "jsonpath", "cli", "json" | ||
| ] | ||
| } |
+11
-14
@@ -1,26 +0,23 @@ | ||
| # jpath | ||
| # jsonpath-cli | ||
| Command Line node application to query JSON using jsonpath | ||
| ## Motivation | ||
| jq is an awsome json query utility however jsonpath has (IMHO) a much simpler query language and easier to learn. I did not find a command line implementation to directly use JSON path queries. | ||
| ### Reference: | ||
| https://www.npmjs.com/package/jsonpath#jsonpath-syntax | ||
| jq is an awsome json query utility however jsonpath has (IMHO) a much simpler query language and easier to learn. I did not find a command line implementation to directly use JSON path queries. | ||
| ## How to install | ||
| 1. Clone the repo | ||
| 2. install globally | ||
| ``` | ||
| npm install -g jsonpath-cli | ||
| ``` | ||
| ## How to execute | ||
| ``` | ||
| npm install -g . | ||
| cat <input.json> | jpath <jsonpath query> | ||
| ``` | ||
| Note: on Windows, the generated jpath.cmd file was incorrect. if you face batch file error, replace the jpath.cmd file with the file in project folder. | ||
| ### Jsonpath query quick Reference: | ||
| 3. Execute using following command | ||
| ``` | ||
| cat input.json | jpath <jsonpath query> | ||
| ``` | ||
| https://www.npmjs.com/package/jsonpath#jsonpath-syntax |
| #!/usr/bin/env node | ||
| require("../cli.js")(process); |
| @ECHO OFF | ||
| SETLOCAL | ||
| SET "NODE_EXE=%~dp0\node.exe" | ||
| IF NOT EXIST "%NODE_EXE%" ( | ||
| SET "NODE_EXE=node" | ||
| ) | ||
| SET "JPATH_JS=%~dp0\node_modules\jpath\bin\index.js" | ||
| "%NODE_EXE%" "%JPATH_JS%" %* |
-45
| module.exports = (process) => { | ||
| process.title = "jpath"; | ||
| const jsonpath = require("jsonpath"); | ||
| const args = process.argv.slice(2); | ||
| //TODO validate args | ||
| //TODO add help https://www.npmjs.com/package/jsonpath#jsonpath-syntax | ||
| if (args.length < 1) { | ||
| console.error("missing arg [query string]"); | ||
| process.exit(1); | ||
| } | ||
| const query = (data) => { | ||
| process.stdout.write( | ||
| JSON.stringify(jsonpath.query(JSON.parse(data), args[0]), null, 2) | ||
| ); | ||
| }; | ||
| //Accept input from standard input | ||
| const readStdIn = () => { | ||
| return new Promise((resolve, reject) => { | ||
| const stdin = process.stdin; | ||
| let data = ""; | ||
| stdin.setEncoding("utf8"); | ||
| stdin.on("data", (chunk) => { | ||
| data += chunk; | ||
| }); | ||
| stdin.on("end", () => { | ||
| resolve(data); | ||
| }); | ||
| stdin.on("error", reject); | ||
| }); | ||
| }; | ||
| if (args.length < 1) { | ||
| process.stdout.write({ message: "missing arg" }); | ||
| } else { | ||
| readStdIn().then(query).catch(console.error); | ||
| } | ||
| }; |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
3149
-8.06%4
-33.33%34
-10.53%24
-7.69%