mirror of
https://github.com/gchq/CyberChef.git
synced 2026-03-17 04:11:51 -07:00
Merge a1ade82420 into 4deaa0de20
This commit is contained in:
commit
1301a8bde0
1 changed files with 20 additions and 7 deletions
|
|
@ -30,7 +30,12 @@ class Jq extends Operation {
|
|||
name: "Query",
|
||||
type: "string",
|
||||
value: ""
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "Raw",
|
||||
type: "boolean",
|
||||
value: false
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -41,12 +46,20 @@ class Jq extends Operation {
|
|||
*/
|
||||
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}`);
|
||||
const [query, raw] = args;
|
||||
if (raw) {
|
||||
const result = await jq.raw(input, query, ["-r"]);
|
||||
if (result.stderr !== "") {
|
||||
throw new OperationError(`Invalid jq expression: ${result.stderr}`);
|
||||
}
|
||||
return result.stdout;
|
||||
} else {
|
||||
try {
|
||||
const result = await jq.json(input, query);
|
||||
return JSON.stringify(result);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Invalid jq expression: ${err.message}`);
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue