{"library":"node-jq","title":"Node.js JQ Wrapper","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-jq"],"cli":null},"imports":["import jq from 'node-jq';","import jq from 'node-jq';\n// then use jq.run(filter, jsonPath, options)","const jq = require('node-jq');\n// then use jq.run(filter, jsonPath, options)","import type { JqOptions } from 'node-jq';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import jq from 'node-jq';\nimport { promises as fs } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { dirname, resolve } from 'node:path';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\nasync function processPokemonData() {\n  const bulbasaurData = {\n    \"id\": 1,\n    \"name\": \"bulbasaur\",\n    \"abilities\": [\n      {\"slot\": 1, \"is_hidden\": false, \"ability\": {\"name\": \"overgrow\", \"url\": \"https://pokeapi.co/api/v2/ability/65/\"}},\n      {\"slot\": 3, \"is_hidden\": true, \"ability\": {\"name\": \"chlorophyll\", \"url\": \"https://pokeapi.co/api/v2/ability/34/\"}}\n    ],\n    \"moves\": [\n      {\"move\": {\"name\": \"tackle\", \"url\": \"https://pokeapi.co/api/v2/move/33/\"}, \"version_group_details\": []}\n    ]\n  };\n\n  const tempFilePath = resolve(__dirname, 'temp-bulbasaur.json');\n  await fs.writeFile(tempFilePath, JSON.stringify(bulbasaurData, null, 2));\n\n  // Filter to get an array of ability names\n  const filterAbilityNames = '.abilities[].ability.name';\n  // Output will be an array of strings like: [\"overgrow\", \"chlorophyll\"]\n\n  try {\n    console.log('--- Extracting Ability Names ---');\n    const abilityNames = await jq.run(filterAbilityNames, tempFilePath, { \n      input: 'file', \n      output: 'json' \n    });\n    console.log('Filtered ability names:', abilityNames);\n\n    // Filter to create a new object with name and an array of move names\n    const filterCustomObject = '{ name: .name, move_names: [.moves[].move.name] }';\n    // Output will be an object like: { \"name\": \"bulbasaur\", \"move_names\": [\"tackle\"] }\n\n    console.log('\\n--- Creating Custom Object with Move Names ---');\n    const customObject = await jq.run(filterCustomObject, tempFilePath, { \n      input: 'file', \n      output: 'json' \n    });\n    console.log('Custom filtered object:', customObject);\n\n  } catch (err) {\n    console.error('Error processing JSON with node-jq:', err);\n  } finally {\n    await fs.unlink(tempFilePath).catch(() => {}); // Clean up temp file\n  }\n}\n\nprocessPokemonData();","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}