Files
CyberChef/src/core/operations/Jq.mjs
T
GCHQDeveloper581andGitHub d9dacf6b8f Fix Jq issue (#2210)
* Revert "fix: jq-web -> jq-wasm, includes jq version 1.8.1 (gchq#2223)"
  This reverts commit 0c6454e.
  (but leave new tests intact)
* Return jq-web to 0.5.1
2026-03-19 11:47:31 +00:00

58 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 jq from "jq-web";
/**
* 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) {
const [query] = args;
let result;
try {
result = jq.json(input, query);
} catch (err) {
throw new OperationError(`Invalid jq expression: ${err.message}`);
}
return JSON.stringify(result);
}
}
export default Jq;