forked from gchq/CyberChef
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from zhzy0077/jq
Adds JQ support
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |