Jsonnet addon for Node.js
npm install @hanazuki/node-jsonnet@hanazuki/node-jsonnet is a libjsonnet binding for Node.js (native addon), which supports all the basic Jsonnet functionality including import and native callbacks (std.native). It also comes with TypeScript type definitions.
``typescript
import { Jsonnet } from "@hanazuki/node-jsonnet";
const jsonnet = new Jsonnet();
// Evaluates a simple Jsonnet program into a JSON value
jsonnet.evaluateSnippet({a: 1 + 2, b: self.a * 3})
.then(json => console.log(JSON.parse(json))); // => { a: 3, b: 9 }
// Jsonnet programs can use JavaScript values through external variables (std.extVar)
// and native callbacks (std.native).
jsonnet.extCode("x", "4")
.nativeCallback("add", (a, b) => Number(a) + Number(b), "a", "b")
.evaluateSnippet(std.extVar("x") * std.native("add")(1, 2))`
.then(json => console.log(JSON.parse(json))); // => 12
The library is documented in the TypeScript type definitions at types/index.d.ts`, and HTML documentation is also available online.
- Node.js v20 or later
- GCC or Clang C++ compiler that supports C++17
- CMake 3.10 or later