Skip to content

Add support for native JSON5 loading of schemas? #102

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

Closed
mondeja opened this issue Jun 3, 2022 · 4 comments
Closed

Add support for native JSON5 loading of schemas? #102

mondeja opened this issue Jun 3, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@mondeja
Copy link
Contributor

mondeja commented Jun 3, 2022

This would be really great because usually there are complex schemas that can only be documented inside multiline comments. There is a $comment keyword added in the draft 7 of JSON Schema but I find it useless for documentation, mainly because the lack of support for structured patterns like lists or code blocks.

The unique problem that I see in a possible implementation is how to parse the null, NaN and Infinity keywords of JSON5, which are beyond JSON limitations. The safest would be, I think, to raise an error if found.

Anyways, I'm not sure if this is beyond of the scope of this project.

Personal current workaround

I'm currently documenting schemas in files apart, but I'm planning to download the JSON5 files in a local folder caching and converting to JSON them, adding that folder to a .gitignore file.

@sirosen
Copy link
Member

sirosen commented Jun 3, 2022

If you install pyjson5 or json5, you'll be able to run on json5 files.

Is this request different from the existing support? The word "native" can mean different things to different people.

@mondeja
Copy link
Contributor Author

mondeja commented Jun 3, 2022

Sorry, maybe I haven't been clear enough. I'm asking for reading of JSON5 schema files, not running using JSON schemas against JSON5 instance files. For example: check-jsonschema pyproject.toml --schemafile pyproject-schema.json5

@sirosen
Copy link
Member

sirosen commented Jun 3, 2022

Ah, no, you were perfectly clear. I was just reading this wrong thinking "but we already have JSON5 support!"
That's my mistake.

I'll need to think about this a little bit. The support for YAML schema definitions is already a potential sticking point for users (see #80 ).
For the short-term, to avoid surprises, there's a pretty hacked-in warning for YAML file $ref usages:

if uri.endswith(".yaml") or uri.endswith(".yml"):

So I need to consider whether or not this can be cleaned up and turned into something more like the instance loading (which is extensible to additional formats by design).

@sirosen sirosen added the enhancement New feature or request label Jun 3, 2022
@sirosen sirosen closed this as completed in 6ca999b Jul 4, 2022
@sirosen
Copy link
Member

sirosen commented Jul 4, 2022

The parser code is now better shared between instances and schemas, and JSON5 parsing of schemas is now supported.

I've just released this as v0.17.0. Please let me know if you see any trouble with it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants