mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-10 00:05:11 -04:00
JSONtoStr
This commit is contained in:
parent
4c3324aea1
commit
829c07b134
2 changed files with 48 additions and 0 deletions
|
@ -354,6 +354,7 @@
|
||||||
"JavaScript Minify",
|
"JavaScript Minify",
|
||||||
"JSON Beautify",
|
"JSON Beautify",
|
||||||
"JSON Minify",
|
"JSON Minify",
|
||||||
|
"JSON Stringify",
|
||||||
"XML Beautify",
|
"XML Beautify",
|
||||||
"XML Minify",
|
"XML Minify",
|
||||||
"SQL Beautify",
|
"SQL Beautify",
|
||||||
|
|
47
src/core/operations/JSONStringify.mjs
Normal file
47
src/core/operations/JSONStringify.mjs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* @author n1073645 [n1073645@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2020
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON Stringify operation
|
||||||
|
*/
|
||||||
|
class JSONStringify extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSONStringify constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "JSON Stringify";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "The JSON.stringify() method converts a JavaScript object or value to a JSON string.";
|
||||||
|
this.infoURL = "https://w3schools.com/js/js_json_stringify.asp";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = JSON.parse(input);
|
||||||
|
} catch (err) {
|
||||||
|
throw new OperationError(err);
|
||||||
|
}
|
||||||
|
return JSON.stringify(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default JSONStringify;
|
Loading…
Add table
Add a link
Reference in a new issue