-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: allow JSON array as input #365
Conversation
@@ -48,7 +48,10 @@ export const preSpawnSchema = Joi.object({ | |||
otherwise: path | |||
}).label('path') | |||
}, | |||
json: (schema) => Joi.object().allow('', null).required().label('json object'), | |||
json: (schema) => Joi.alternatives().try( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure If I understand this change correctly. Isn't there any Joi.json instead?
I thought that Joi.object()
would treat as JS Object so, same as typeof [] === 'object'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that doesn't seem to be the case. If I send an array as input I get an error
ValidationError: "json object" must be of type object
You can checkout my test cases (99f8ae6) to see what I'm trying to do.
Brief example:
const jq = require('node-jq')
obj = ["asdf","test"]
jq.run(".", JSON.stringify(obj), {'input': 'json'})
.then( out => {
console.log("out:", out)
})
.catch( err => {
console.error(err.message)
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, totally get the why. I even wonder why do we even need Joi for the input tbh.
But this PR looks good.
I would add a breaking change since it does change the API surface. Maybe doable thought the commit, let me know if you need help with this, otherwise, I'm merging it. |
|
BREAKING CHANGE: allow json array as input
🎉 This PR is included in version 2.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
As described in #363, node-jq currently does not allow JSON arrays as input.
This PR:
It's worth considering allow even more input, since any JSON object is effectively allowed by jq.
The only issue I can think of right now is with
undefined
: