This is a library for Node.js that provides C bindings to the jq library. It allows you to use jq to extract and manipulate data from JSON objects in Node.js.
To use this library, you must have node-gyp
installed on your system. and the following libraries
-
node-gyp
npm install -g node-gyp
-
XCode on Mac, gcc on unix Mac
xcode-select --install
Yum
sudo yum install gcc g++
apt-get
sudo apt-get gcc g++
-
The following C\C++ toolchains autoconf make libtool automake Homebrew
brew install autoconf make automake libtool
Yum
sudo apt-get install -y autoconf make libtool automake
apt-get
sudo apt-get install -y autoconf make libtool automake
-
If the main
python
version used by your system is3.12
or higher, you will also need to make sure you havesetuptools
installed (see here):python3 -m pip install setuptools
npm install @port-labs/jq-node-bindings
Here's an example of how to use the library:
import { exec } from '@port-labs/jq-node-bindings';
const json = { foo: 'bar' };
const input = '.foo';
const result = exec(json, input);
console.log(result); // outputs "bar"
The exec function takes two arguments: a JSON object and a jq input string. It returns the result of running the jq program on the JSON object. The result can be of any type supported by jq: object, array, string, number, boolean, or null.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.