1.0.1 β€’ Published 6 months ago

jq-wasm v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

jq-wasm

jq-wasm is a WebAssembly-powered version of the powerful jq JSON processor, built using Emscripten. It allows you to use jq directly in Node.js or modern browsers without requiring any native dependencies.

Whether you’re filtering, transforming, or querying JSON data, jq-wasm brings the versatility of jq to your JavaScript/TypeScript projects.

πŸš€ Features

  • Node.js and Browser Support: Run jq in both server-side and client-side environments.
  • No Native Dependencies: Works seamlessly without additional libraries or build tools.
  • Fully Typed: Includes TypeScript definitions for a smooth development experience.
  • Familiar jq API: Supports standard jq filters and flags.

πŸ“¦ Installation

Install with npm:

npm install jq-wasm

or with Yarn:

yarn add jq-wasm

πŸ› οΈ Usage

const jq = require("jq-wasm");
// or using ES modules:
// import jq from "jq-wasm";

(async () => {
  try {
    // Example JSON input
    const input = { foo: "bar", list: [1, 2, 3] };

    // Using jq.raw for raw text output
    const rawResult = await jq.raw(input, ".list | .[]", ["-c"]);
    console.log(rawResult); // Output: "1\n2\n3"

    // Using jq.json for parsed JSON output
    const result = await jq.json(input, ".foo");
    console.log(result); // Output: ["bar"]
  } catch (err) {
    console.error("Error:", err.message);
  }
})();

πŸ“– API

jq.raw(input, filter, [flags])

Executes a jq filter and returns raw string output, exactly as jq would produce.

Parameters

  • input: A JavaScript object or array (the JSON input).
  • filter: A jq filter string.
  • flags (optional): An array of jq command-line flags.

Returns

A Promise that resolves to:

  • Raw string: The jq output as a plain text string.

jq.json(input, filter, [flags])

Executes a jq filter on a JSON object and returns parsed JSON results.

Parameters

  • input: A JavaScript object or array (the JSON input).
  • filter: A jq filter string (e.g., .foo, .[].bar, etc.).
  • flags (optional): An array of jq command-line flags (e.g., ["-c"] for compact output).

Returns

A Promise that resolves to:

  • Single parsed JSON object or array: For a single jq result.
  • Array of parsed JSON objects or arrays: For multiple results.

πŸ“š License

This project is licensed under the MIT License.

🌟 Contributions

Contributions, issues, and feature requests are welcome! Feel free to check out the issues page.

1.0.1

6 months ago

1.0.0

6 months ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago