{"name":"node-jq","version":"6.2.0","keywords":["jq","json"],"author":{"name":"sanack"},"license":"MIT","_id":"node-jq@6.2.0","maintainers":[{"name":"mackermans-admin","email":"maarten.ackermans@gmail.com"},{"name":"davesnx","email":"dsnxmoreno@gmail.com"}],"contributors":[{"name":"davesnx","email":"dsnxmoreno@gmail.com"},{"name":"mackermans","email":"maarten.ackermans@gmail.com"}],"homepage":"https://github.com/sanack/node-jq#readme","bugs":{"url":"https://github.com/sanack/node-jq/issues"},"bin":{"node-jq":"bin/node-jq"},"dist":{"shasum":"ed5dfe04af1a575bf8d059fa32c5c974f7768d84","tarball":"http://registry-npm.ywwl.com/node-jq/download/node-jq-6.2.0.tgz","fileCount":15,"integrity":"sha512-z58JGK3N44HwWXV9xD48+lS3wNsgRNsdPzwGFT0KVFCs2KtiOz9gLbXBmg1CT1PXEPP2kdpwpFJ+t9Ie3WNYzQ==","signatures":[{"sig":"MEQCIElcDWFkq81WRKG8AODV7Dg92hZR5pGYLZyoMFdR8tikAiAtkoyXOd6UJDotnV71nM/uVlNVd7M1ecY44hE7DXSjVg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":87173,"size":56440,"noattachment":false,"key":"/node-jq/-/node-jq-6.2.0.tgz"},"main":"lib/jq.js","types":"./lib/jq.d.ts","engines":{"node":">= 18"},"gitHead":"6f3e31b9afb7504a5ae2eea1e2f392bb35697bac","scripts":{"lint":"eslint .","test":"nyc mocha src/*.test.ts -r @swc-node/register","build":"swc ./src --delete-dir-on-start -d lib --strip-leading-paths && tsc","pretest":"npm run install-binary","coverage":"nyc report --reporter=lcov","typecheck":"tsc --noEmit","preinstall":"npm run install-binary","test:watch":"npm test -- --watch","codeclimate":"codeclimate-test-reporter < coverage/lcov.info","install-binary":"node scripts/install-binary.mjs","precodeclimate":"npm run coverage","semantic-release":"semantic-release"},"_npmUser":{"name":"davesnx","email":"dsnxmoreno@gmail.com"},"repository":{"url":"git+https://github.com/sanack/node-jq.git","type":"git"},"_npmVersion":"9.8.1","description":"Run jq in node","directories":{},"_nodeVersion":"22.18.0","dependencies":{"tar":"^7.4.0","zod":"^3.23.8","tempy":"^3.1.0","is-valid-path":"^0.1.1","strip-final-newline":"^2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","chai":"^4.2.0","mocha":"^10.0.0","eslint":"^8.57.0","snazzy":"^9.0.0","@swc/cli":"^0.4.0","lefthook":"^1.12.3","prettier":"3.3.2","@swc/core":"^1.2.161","copyfiles":"^2.4.1","typescript":"^5.5.3","@types/chai":"^4.3.16","@types/node":"^18.19.39","@types/mocha":"^10.0.7","@types/eslint":"^8.56.10","@tsconfig/node18":"^18.2.4","semantic-release":"^23.0.0","@swc-node/register":"^1.10.2","@tsconfig/strictest":"^2.0.5","validate-commit-msg":"^2.14.0","@types/is-valid-path":"^0.1.2","@semantic-release/npm":"^10.0.4","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3","@semantic-release/github":"^9.0.4","@typescript-eslint/parser":"^7.15.0","codeclimate-test-reporter":"^0.5.1","@types/strip-final-newline":"^2.0.0","@semantic-release/changelog":"^6.0.3","@typescript-eslint/eslint-plugin":"^7.15.0","@semantic-release/commit-analyzer":"^12.0.0","@semantic-release/release-notes-generator":"^11.0.4","conventional-changelog-conventionalcommits":"^7.0.0"},"_npmOperationalInternal":{"tmp":"tmp/node-jq_6.2.0_1756496283362_0.5728107151789081","host":"s3://npm-registry-packages-npm-production"},"readme":"<br/>\n<img width=\"300\" alt=\"node-jq logo\" src=\"docs/assets/logo-with-margin.png\" />\n\n![https://www.npmjs.com/package/node-jq](https://img.shields.io/npm/dm/node-jq.svg?maxAge=3600)\n![https://www.npmjs.com/package/node-jq](https://img.shields.io/npm/v/node-jq.svg?maxAge=3600)\n![https://codeclimate.com/github/sanack/node-jq/coverage](https://codeclimate.com/github/sanack/node-jq/badges/coverage.svg)\n![https://github.com/sanack/node-jq/actions/workflows/ci.yml](https://github.com/sanack/node-jq/actions/workflows/ci.yml/badge.svg)\n\n[node-jq](https://github.com/sanack/node-jq) is a Node.js wrapper for [jq](https://jqlang.github.io/jq/) - a lightweight and flexible command-line JSON processor\n\n---\n\n## Installation\n\n```bash\n$ npm install node-jq --save\n# or\n$ yarn add node-jq\n# or\n$ pnpm install node-jq\n```\n\n## Fast\n\nYou can use `jq` directly with `npx`:\n\n```bash\nnpx node-jq '.foo' package.json\n```\n\n## Advanced installation\n\nBy default, `node-jq` downloads `jq` during the installation process with a post-install script. Depending on your OS it downloads from [https://github.com/jqlang/jq/releases] into `./node_modules/node-jq/bin/jq` to avoid colisions with any global installation. Check #161 #167 #171 for more information. You can safely rely on this location for your installed `jq`, we won't change this path without a major version upgrade.\n\n### Skipping binary installation and use your local jq\n\nIf you want to skip the installation step of `jq`, you can do it with different mechanisms. `node-jq` will assume `jq` is in `$PATH` when skipping the installation.\n\nChoose the one that fits best your needs:\n\n- Ignore the installation by not running it with: `npm install node-jq --ignore-scripts`\n  ```bash\n  npm install node-jq --ignore-scripts\n  ```\n- Set `NODE_JQ_SKIP_INSTALL_BINARY` environment variable to `true`.\n  ```bash\n  export NODE_JQ_SKIP_INSTALL_BINARY=\"true\"\n  npm install node-jq\n  ```\n- Set `JQ_PATH` environment variable\n  ```bash\n  export JQ_PATH=\"../../jq\"\n  npm install node-jq\n  ```\n- Set `jq_path` in `.npmrc` (npm config files https://docs.npmjs.com/cli/v8/configuring-npm/npmrc)\n  ```t\n  # .npmrc\n  jq_path=/usr/local/bin/jq\n  ```\n  ```bash\n  npm install node-jq\n  ```\n\n## Usage\n\n### jq example\n\nUsually in your CLI using `jq`:\n\n```bash\njq \".abilities[].moves\" bulbasaur.json\n```\n\nand you get\n\n```bash\n{\n  \"name\": \"heartgold-soulsilver\",\n  \"power\": \"10\"\n}\n{\n  \"name\": \"platinum\",\n  \"power\": \"50\"\n}\n{\n  \"name\": \"diamond-pearl\",\n  \"power\": \"99\"\n}\n```\n\n#### node-jq equivalent\n\nWith `node-jq` you could run it programmatically and interact with the output as a [JavaScript Object](http://javascript.info/tutorial/objects):\n\n> NOTE: Take care of the filter that you are using with `jq`, mapping an array or any other iterative output isn't a valid JavaScript Object, that might fail at parse-time.\n\n```javascript\nconst jq = require('node-jq')\n\nconst filter = '.abilities[].moves'\nconst jsonPath = '/path/to/bulbasaur.json'\nconst options = {}\n\njq.run(filter, jsonPath, options)\n  .then((output) => {\n    console.log(output)\n    /*\n      {\n        \"name\": \"heartgold-soulsilver\",\n        \"power\": \"10\"\n      },\n      {\n        \"name\": \"platinum\",\n        \"power\": \"50\"\n      },\n      {\n        \"name\": \"diamond-pearl\",\n        \"power\": \"99\"\n      }\n    */\n  })\n  .catch((err) => {\n    console.error(err)\n    // Something went wrong...\n  })\n```\n\n## Options\n\n### path to jq binary\n\nBy default, the `jq` binary installed with the package is used. You can override this in several ways:\n\n1. **`.npmrc` configuration** (recommended for project-level settings):\n   ```bash\n   jq-path=jq\n   # or\n   jq-path=/usr/local/bin/jq\n   ```\n\n2. **Environment variable** (for runtime overrides):\n   ```bash\n   export JQ_PATH=/path/to/jq\n   ```\n\nThe priority order is: `JQ_PATH` environment variable → `.npmrc` configuration → downloaded binary.\n\n### input\n\n|  Description  |  Type  |             Values             |  Default |\n|:-------------:|:------:|:------------------------------:|:--------:|\n| Type of input | string | `'file'`, `'json'`, `'string'` | `'file'` |\n\n#### `input: 'file'`\n\nRun the jq query against a **JSON file**.\n\n```javascript\njq.run('.', '/path/to/file.json').then(console.log)\n// { \"foo\": \"bar\" }\n```\n\n#### `input: 'file'` with multiple files\n\nRun jq query against multiple **JSON files**.\n\n```javascript\njq.run('.', ['/path/to/file.json','path/to/other_file.json']).then(console.log)\n// { \"foo\": \"bar\" }\n// { \"otherFoo\": \"andBar\" }\n```\n\n#### `input: 'json'`\n\nRun the `jq` query against an **Object**.\n\n```javascript\njq.run('.', { foo: 'bar' }, { input: 'json' }).then(console.log)\n// { \"foo\": \"bar\" }\n\n```\n\n#### `input: 'string'`\n\nRun the jq query against a **String**.\n\n```javascript\njq.run('.', '{ foo: \"bar\" }', { input: 'string' }).then(console.log)\n// { \"foo\": \"bar\" }\n```\n\n---\n\n### output\n\n| Description    | Values                                        | Default    |\n|:--------------:|:---------------------------------------------:|:----------:|\n| Type of output | `'pretty'`, `'json'`, `'compact'`, `'string'` | `'pretty'` |\n\n#### `output: 'pretty'`\n\nReturn the output as a **String**.\n\n```javascript\njq.run('.', '/path/to/file.json', { output: 'string' }).then(console.log)\n// {\n//   \"foo\": \"bar\"\n// }\n```\n\n#### `output: 'json'`\n\nReturn the output as an **Object**.\n\n```javascript\njq.run('.', '/path/to/file.json', { output: 'json' }).then(console.log)\n// { foo: 'bar' }\n```\n\n#### `output: 'compact'|'string'`\n\nReturn the output as a **String**.\n\n```javascript\njq.run('.', '/path/to/file.json', { output: 'compact' }).then(console.log)\n// {\"foo\":\"bar\"}\njq.run('.', '/path/to/file.json', { output: 'string' }).then(console.log)\n// {\"foo\":\"bar\"}\n```\n\n---\n\n### slurp\n\n|         Description          |     Values      | Default |\n|:----------------------------:|:---------------:|:-------:|\n| Read input stream into array | `true`, `false` | `false` |\n\n#### `slurp: true`\n\nRead input stream into array.\n\n```javascript\njq.run('.', ['/path/to/file.json','/path/to/other_file.json'], { output: 'json', slurp: true }).then(console.log)\n// [\n//   {\n//     \"foo\": \"bar\"\n//   },\n//   {\n//     \"otherFoo\": \"andBar\"\n//   }\n// ]\n```\n\n### sort\n\n|         Description                   |     Values      | Default |\n|:-------------------------------------:|:---------------:|:-------:|\n| Sort object keys in alphabetical order| `true`, `false` | `false` |\n\n#### `sort: true`\n\nSorts object keys alphabetically.\n\n```javascript\njq.run('.', ['/path/to/file.json'], { output: 'json', sort: true }).then(console.log)\n// {\n//   \"a\": 2,\n//   \"b\": 1\n// },\n```\n\n### args\n\n|         Description                   |        Values        |   Default   |\n|:-------------------------------------:|:--------------------:|:-----------:|\n| Send custom args to the jq command    | `[object]`           | `undefined` |\n\n#### `args: { myfruit: { hello: 'orange'}, myfruit2: \"banana\" }`\n\nAdds the `--argjson myfruit \"{ 'hello': 'orange' }\" --arg myfruit2 orange` arguments to the internal jq command\n\n```javascript\njq.run('{\"fruit\":$myfruit,\"fruit2\":$myfruit2}', ['/path/to/file.json'], { output: 'json', sort: true, args: { myfruit: { hello: 'orange' }, myfruit2: \"banana\" } }).then(console.log)\n// {\n//   fruit: {\n//      hello: \"orange\"\n//   },\n//   fruit2: \"banana\"\n// }\n```\n\n### cwd\n\n|           Description            |   Values   |    Default    |\n|:--------------------------------:|:----------:|:-------------:|\n| Set working dir for `jq` process | valid path | process.cwd() |\n\n\n```javascript\njq.run('.', ['file.json'], { output: 'json', sort: true }, '/path/to').then(console.log)\n// {\n//   \"a\": 2,\n//   \"b\": 1\n// },\n```\n\n### detached\n\n|             Description              |     Values      | Default  |\n|:------------------------------------:|:---------------:|:--------:|\n| Run `jq` process as detached process | `true`, `false` | `false`  |\n\nBy default `jq` process will run 'attached' to the main process. That means that any interrupt signal main process receives will be propagated to `jq` process. For example, if main process receives `SIGTERM`, `jq` will also receive it and exit immediately.\n\nHowever, in some cases you might **not** want `jq` to exit immediately and let it exit normally. For example, if you want to implement a graceful shutdown - main process receives `SIGTERM`, it finishes processing current json file and exits after processing is completed.\n\nTo achieve that run `jq` detached and NodeJS will not propagate `SIGTERM` to `jq` process allowing it to run until it completes.\n\n```javascript\njq.run('.', ['file.json'], { output: 'json', sort: true }, undefined, true).then(console.log)\n// {\n//   \"a\": 2,\n//   \"b\": 1\n// },\n```\n\n## Projects using **node-jq**\n\n- **[atom-jq](https://github.com/sanack/atom-jq)**: an [Atom](https://atom.io/) package for manipulating JSON\n- **[json-splora](https://github.com/wellsjo/JSON-Splora)**: an [Electron](http://electron.atom.io/) implementation for manipulating JSON\n- [Check more](https://github.com/sanack/node-jq/network/dependents?package_id=UGFja2FnZS0xNTIxMzU1MQ%3D%3D)\n\n## Why?\n\nWhy would you want to manipulate JavaScript Objects with `jq` inside a nodejs app, when there are tools like [ramda](https://ramdajs.com) or [lodash](lodash.com)?\n\nThe idea was to port `jq` in node to be able to run it as-is. `node-jq` doesn't try to replace `Array`/`Object` filters, maps, transformations, and so on.\n\nOur primary goal was to make `jq` syntax available inside an [Atom](https://atom.io/) extension: [atom-jq](https://github.com/sanack/atom-jq).\n\nOther than that, `jq` is an interesting CLI tool to quickly parse and manipulate the response of an API, such as:\n\n```bash\ncurl 'https://jsonplaceholder.typicode.com/comments' | jq '.[].postId'\n```\n\nThere are also people dealing with complex use-cases, and some of them want to port their bash scripts to node:\n\n- [ilya-sher.org/2016/05/11/most-jq-you-will-ever-need](https://ilya-sher.org/2016/05/11/most-jq-you-will-ever-need/)\n- [cloudadvantage.com.au/new-aws-command-line-tool-and-jq](http://www.cloudadvantage.com.au/new-aws-command-line-tool-and-jq/)\n\n## Want to learn `jq`?\n\nSeems hard to learn, but it really isn't.\n\n`jq` is like `sed` for `JSON`. *Slice*, *filter*, *map* and *transform* structured data in a **simple** and **powerful** way.\n\nTake a look at [this great introduction](https://robots.thoughtbot.com/jq-is-sed-for-json) or a [jq lesson](http://programminghistorian.org/lessons/json-and-jq).\n\nYou can check out the [official manual](https://jqlang.github.io/jq/manual) and fiddle around in the online playground [jqplay.org](https://jqplay.org).\n\n## License\n\n[License](./LICENSE.md)\n","publish_time":1756496283579,"_cnpm_publish_time":1756496283579,"dist-tags":{"beta":"6.2.1-beta.3","latest":"6.3.1","next":"4.1.0-rc.3"}}