-
-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
Description
When passing an object with undefined properties to jq.run(), node-jq throws a ZodError instead of handling the case gracefully. This occurs with any jq filter.
Environment
- TypeScript
- node-jq version: 6.0.1
- Node.js version: v22.15.1
- Platform: Linux
Minimal Reproduction
import jq from "node-jq";
async function reproduceZodError() {
const data = { x: undefined, y: "hello" };
try {
const result = await jq.run('.', data, { input: "json", output: "json" });
console.log("Success:", result);
} catch (error) {
console.log("ZodError occurred:", error.message);
}
}
reproduceZodError();Expected Behavior
I suppose there are several behaviors that could be considered valid:
- Treating
undefinedasnull - Filtering out
undefinedproperties likeJSON.stringify() - Specific error message
Actual Behavior
Throws a ZodError with validation errors:
ZodError: [
{
"code": "invalid_union",
"unionErrors": [
// ... lots of nested errors
],
"path": ["json", "x"],
"message": "Invalid input"
}
]
Workaround
Remove undefined values before processing:
function removeUndefined(obj) {
return JSON.parse(JSON.stringify(obj));
}
const cleanData = removeUndefined(originalData);
const result = await jq.run('.', cleanData, { input: "json", output: "json" });PS: Part of this was written by Claude Code; it also helped identify the bug.
Metadata
Metadata
Assignees
Labels
No labels