Skip to content

Commit 4290ea7

Browse files
authored
fix: use js-yaml for both JSON to YAML and YAML to JSON (gchq#2710)
1 parent e2b0558 commit 4290ea7

4 files changed

Lines changed: 81 additions & 10 deletions

File tree

package-lock.json

Lines changed: 74 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"jquery": "3.7.1",
143143
"js-ascon": "^1.3.0",
144144
"js-sha3": "^0.12.0",
145+
"js-yaml": "^5.2.3",
145146
"jsesc": "^3.1.0",
146147
"json5": "^2.2.3",
147148
"jsonata": "^2.2.2",

src/core/operations/JSONtoYAML.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import Operation from "../Operation.mjs";
88
import OperationError from "../errors/OperationError.mjs";
9-
import YAML from "yaml";
9+
import { dump } from "js-yaml";
1010

1111
/**
1212
* JSON to YAML operation
@@ -35,9 +35,9 @@ class JSONtoYAML extends Operation {
3535
*/
3636
run(input, args) {
3737
try {
38-
return YAML.stringify(input);
38+
return dump(input);
3939
} catch (err) {
40-
throw new OperationError("Test");
40+
throw new OperationError("Unable to stringify YAML: " + err);
4141
}
4242
}
4343

src/core/operations/YAMLToJSON.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import Operation from "../Operation.mjs";
88
import OperationError from "../errors/OperationError.mjs";
9-
import jsYaml from "js-yaml";
9+
import { load } from "js-yaml";
10+
1011
/**
1112
* YAML to JSON operation
1213
*/
@@ -34,7 +35,7 @@ class YAMLToJSON extends Operation {
3435
*/
3536
run(input, args) {
3637
try {
37-
return jsYaml.load(input);
38+
return load(input);
3839
} catch (err) {
3940
throw new OperationError("Unable to parse YAML: " + err);
4041
}

0 commit comments

Comments
 (0)