Skip to content
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

Validate JSON repr against JSON schema #38

Open
sim642 opened this issue Dec 10, 2021 · 2 comments
Open

Validate JSON repr against JSON schema #38

sim642 opened this issue Dec 10, 2021 · 2 comments

Comments

@sim642
Copy link

sim642 commented Dec 10, 2021

I was looking for an OCaml library to validate Yojson objects against a JSON schema and this library looks like the only one remotely related to that task. Unfortunately, I cannot figure out how to do it and am not suspecting it's not actually provided as a feature.

Json_schema does allow parsing JSON schemas from JSON objects themselves. Json_encoding implements all the validation rules, but that's on statically typed encodings, not arbitrary runtime schemas, which is what I want.
But there doesn't seem to be a way to convert a Json_schema.schema to any kind of Json_encoding.encoding, which would actually validate objects against the schema when destructing. There's custom, but that just stores the schema without checking.

Am I missing something or is it impossible to use this library for arbitrary schema validation?

@maxtori
Copy link
Collaborator

maxtori commented Dec 10, 2021

This repo is not maintained anymore, the successor is json-data-encoding.
Regarding validation of schema, it is not handled unfortunately, there is a nice commentary (* TODO: validator *) in the file json_schema.ml, but I don't think anybody is working on it.

@sim642
Copy link
Author

sim642 commented Dec 13, 2021

This repo is not maintained anymore, the successor is json-data-encoding. Regarding validation of schema, it is not handled unfortunately, there is a nice commentary (* TODO: validator *) in the file json_schema.ml, but I don't think anybody is working on it.

Thanks for pointing that out! This repo looked inactive indeed, but it wasn't obvious that there's a successor somewhere.

Seems like I might be able to define a function Json_schema.schema -> unit Json_encoding.encoding (for at least the basic constructs I'm interested in) to have a type- and value-erased encoding, which on destruct at least checks the representation and signals invalidity through Cannot_destruct. Kind of hacky, but hopefully less work than writing everything from scratch for the time being.

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

No branches or pull requests

2 participants