mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-24 08:46:19 -04:00
Support jq.
This commit is contained in:
parent
6ed9d4554a
commit
d2da11c79a
4 changed files with 70 additions and 0 deletions
|
@ -422,6 +422,7 @@
|
|||
"CSS Minify",
|
||||
"XPath expression",
|
||||
"JPath expression",
|
||||
"Jq",
|
||||
"CSS selector",
|
||||
"PHP Deserialize",
|
||||
"Microsoft Script Decoder",
|
||||
|
|
57
src/core/operations/Jq.mjs
Normal file
57
src/core/operations/Jq.mjs
Normal file
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* @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 = "Code";
|
||||
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;
|
Loading…
Add table
Add a link
Reference in a new issue