Add support for comments inside JSON
ale5000-git opened this issue · 3 comments
What version of Ajv you are you using?
v8.17.1
What problem do you want to solve?
Visual Studio Code use tasks.json that support comments in these forms:
// Comment
/*
Comment
*/
Example:
{
// Comment
"version": "2.0.0",
"tasks": [
{
"label": "build"
}
]
}
Could you please add an option to validate with comments?
What do you think is the correct solution to problem?
Add an option.
Will you be able to implement it?
No.
Hi @ale5000-git, so I understand that VSCode supports a custom, non-standard, version of JSON that allows comments and you would like AJV to support it too? This would require custom implementation to be supported in AJV and every new feature or options adds to the complexity and overall footprint of the library. For this reason I don't think the code for this should live within AJV when it is pretty trivial to do your own preprocessing of schema to support it within your project. You could write JSON schema with comments and have a job you run before schema compilation (or running of your project) that strips out the comments.
Also another thing to consider is that you can also write schema for AJV in javascript which you can comment. Just write them as a javascript module that exports the schema as a javascript object and import it and use it with AJV.
I'll leave this open for a bit to see if anyone else has thoughts on it, but my instinct is to not support this.
so I understand that VSCode supports a custom, non-standard, version of JSON that allows comments and you would like AJV to support it too?
Yes, and the auto-generated json contain comments.
Isn't possible to add a command line option to generically support comments on the currently selected schema?
Maybe just a preprocessing phase that strip only valid comments.
It is possible, but it's also just as possible to write your own build step however you like, or to write a small lib or cli tool to do it. You have to remember that every bit of code added to AJV adds to the complexity of the project, it adds to the code footprint that needs to be maintained and adds to options that need to be documented. Given how many projects rely on AJV we need to be very picky about what we add to it.