Skip to content

Commit a1ade82

Browse files
feat: add Raw option for Jq operation
1 parent d195a51 commit a1ade82

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/core/operations/Jq.mjs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ class Jq extends Operation {
3030
name: "Query",
3131
type: "string",
3232
value: ""
33-
}
33+
},
34+
{
35+
name: "Raw",
36+
type: "boolean",
37+
value: false
38+
},
3439
];
3540
}
3641

@@ -41,12 +46,20 @@ class Jq extends Operation {
4146
*/
4247
run(input, args) {
4348
return (async () => {
44-
const [query] = args;
45-
try {
46-
const result = await jq.json(input, query);
47-
return JSON.stringify(result);
48-
} catch (err) {
49-
throw new OperationError(`Invalid jq expression: ${err.message}`);
49+
const [query, raw] = args;
50+
if (raw) {
51+
const result = await jq.raw(input, query, ["-r"]);
52+
if (result.stderr !== "") {
53+
throw new OperationError(`Invalid jq expression: ${result.stderr}`);
54+
}
55+
return result.stdout;
56+
} else {
57+
try {
58+
const result = await jq.json(input, query);
59+
return JSON.stringify(result);
60+
} catch (err) {
61+
throw new OperationError(`Invalid jq expression: ${err.message}`);
62+
}
5063
}
5164
})();
5265
}

0 commit comments

Comments
 (0)