mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-08 07:21:02 -04:00
test pass
This commit is contained in:
parent
5c4f8e5d87
commit
7f2355b782
5 changed files with 78 additions and 11 deletions
|
@ -3,12 +3,6 @@
|
|||
"name": "Favourites",
|
||||
"ops": []
|
||||
},
|
||||
{
|
||||
"name": "Wangkechun",
|
||||
"ops": [
|
||||
"JSON To Go Struct"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Data format",
|
||||
"ops": [
|
||||
|
@ -420,6 +414,7 @@
|
|||
"JavaScript Minify",
|
||||
"JSON Beautify",
|
||||
"JSON Minify",
|
||||
"JSON to Go Struct",
|
||||
"XML Beautify",
|
||||
"XML Minify",
|
||||
"SQL Beautify",
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import { jsonToGo } from "../lib/JSONToGoStruct.mjs";
|
||||
import { jsonToGo } from "../vendor/JSONToGoStruct.mjs";
|
||||
import JSON5 from "json5";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* JSON To Go Struct operation
|
||||
* JSON to Go Struct operation
|
||||
*/
|
||||
class JSONToGoStruct extends Operation {
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ class JSONToGoStruct extends Operation {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "JSON To Go Struct";
|
||||
this.name = "JSON to Go Struct";
|
||||
this.module = "Default";
|
||||
this.description = "converts JSON into a Go type definition.";
|
||||
this.infoURL = "https://mholt.github.io/json-to-go/";
|
||||
|
@ -34,7 +34,7 @@ class JSONToGoStruct extends Operation {
|
|||
{
|
||||
name: "Flatten",
|
||||
type: "boolean",
|
||||
value: false,
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: "All Omit Empty",
|
||||
|
@ -59,7 +59,7 @@ class JSONToGoStruct extends Operation {
|
|||
throw new OperationError("Unable to parse input as JSON.\n" + err);
|
||||
}
|
||||
const result = jsonToGo(code, typename, flatten, false, allOmitempty);
|
||||
return result["go"];
|
||||
return result.go;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -171,6 +171,9 @@ export function jsonToGo(
|
|||
++innerTabs;
|
||||
const keys = Object.keys(scope);
|
||||
for (let i in keys) {
|
||||
if (!Object.prototype.hasOwnProperty.call(keys, i)) {
|
||||
continue;
|
||||
}
|
||||
const keyname = getOriginalName(keys[i]);
|
||||
indenter(innerTabs);
|
||||
const typename = uniqueTypeName(format(keyname), seenTypeNames);
|
||||
|
@ -195,6 +198,9 @@ export function jsonToGo(
|
|||
++tabs;
|
||||
const keys = Object.keys(scope);
|
||||
for (let i in keys) {
|
||||
if (!Object.prototype.hasOwnProperty.call(keys, i)) {
|
||||
continue;
|
||||
}
|
||||
const keyname = getOriginalName(keys[i]);
|
||||
indent(tabs);
|
||||
const typename = uniqueTypeName(format(keyname), seenTypeNames);
|
||||
|
@ -450,6 +456,9 @@ export function jsonToGo(
|
|||
|
||||
function formatScopeKeys(keys) {
|
||||
for (let i in keys) {
|
||||
if (!Object.prototype.hasOwnProperty.call(keys, i)) {
|
||||
continue;
|
||||
}
|
||||
keys[i] = format(keys[i]);
|
||||
}
|
||||
return keys;
|
Loading…
Add table
Add a link
Reference in a new issue