node-jq is a Node.js wrapper that allows developers to programmatically execute `jq`, the lightweight and flexible command-line JSON processor. It handles the installation of the `jq` binary by default during the `npm install` process, placing it within the package's `node_modules` directory to avoid global conflicts. Users can also configure it to use an existing `jq` binary via environment variables or `.npmrc`. The package currently stands at version 6.3.1 (as of late August 2025) and exhibits an active release cadence with frequent bug fixes and minor feature updates. Its primary differentiator is providing a simple, promise-based API to interact with `jq`'s powerful JSON querying capabilities directly within Node.js applications, abstracting away the complexities of child process management and binary execution. It ships with TypeScript types, facilitating modern development workflows.
npm install node-jqVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `node-jq` to process a local JSON file. It shows two examples: one extracting a list of ability names into a JavaScript array, and another constructing a new JavaScript object containing the Pokémon's name and an array of its move names. It includes setup for creating a temporary JSON file, error handling, and cleanup.
Ensure post-install scripts are enabled during installation. Alternatively, manually provide the `jq` binary path via the `JQ_PATH` environment variable or by configuring `jq-path` in your project's `.npmrc` file.
Craft `jq` filters carefully to ensure the output is a single, valid JSON document (e.g., wrap iterative outputs in an array like `[.[]]`). If processing multiple `jq` outputs as a stream is required, consider an alternative approach or process `node-jq`'s raw string output directly.
Verify that `JQ_PATH` points to a valid `jq` executable or that `jq-path` in `.npmrc` is correctly configured and accessible in your environment. Remember that `JQ_PATH` overrides `.npmrc`.
Upgrade your Node.js environment to version 18 or newer to ensure compatibility and leverage modern JavaScript features.
Ensure that post-install scripts are enabled when installing `node-jq`. If using a custom path, verify that `JQ_PATH` environment variable or `jq-path` in `.npmrc` correctly specifies the absolute path to a functional `jq` executable.
Adjust your `jq` filter to always produce a single, well-formed JSON document. For example, to output an array of objects, use `[.[]]` at the end of your filter. If you need to process multiple individual JSON documents, retrieve the output as a string (`output: 'string'`) and parse it manually.
For ESM, ensure you use `import jq from 'node-jq';`. For CommonJS, use `const jq = require('node-jq');`. The `run` function is a method on the default export, not a named export or a standalone function.