William Floyd 0c6454e10c
fix: jq-web -> jq-wasm, includes jq version 1.8.1 (#2223)
Co-authored-by: GCHQDeveloper581 <63102987+GCHQDeveloper581@users.noreply.github.com> (added tests)
2026-03-06 12:04:41 +00:00

57 lines
1.2 KiB
JavaScript

/**
* @author zhzy0077 [zhzy0077@hotmail.com]
* @copyright Crown Copyright 2023
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import * as jq from "jq-wasm";
/**
* jq operation
*/
class Jq extends Operation {
/**
* Jq constructor
*/
constructor() {
super();
this.name = "Jq";
this.module = "Jq";
this.description = "jq is a lightweight and flexible command-line JSON processor.";
this.infoURL = "https://github.com/jqlang/jq";
this.inputType = "JSON";
this.outputType = "string";
this.args = [
{
name: "Query",
type: "string",
value: ""
}
];
}
/**
* @param {JSON} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
return (async () => {
const [query] = args;
try {
const result = await jq.json(input, query);
return JSON.stringify(result);
} catch (err) {
throw new OperationError(`Invalid jq expression: ${err.message}`);
}
})();
}
}
export default Jq;