Closed alexdewar closed 5 months ago
You're brave :-)
While the jsonschema library depends largely on the type requirements of the template parameter Json
, and not specifically on the implementation details of jsoncons::basic_json
, jsoncons::basic_json
and nlohmann::basic_json
have different type properties. They have some similarities where they're both following the standard library, e.g. contains()
, size()
, at()
, find()
, but there is nothing in the standard library that's like a container that supports both a vector-like and map-like interface, and here jsoncons and nlohmann take different approaches.
To make this work, you'd have to write an adaptor that adapts a nlohmann::basic_json
to the type requirements of the jsonschema library, but that would be hard, as we haven't formally defined what those type requirements are. At some point I want to be able to use the library with a different, read-only, representation of JSON (which allows for very fast parsing), so I am thinking about this. But for now I don't think it's realistic. I think if you do want to use this library for schema validation only, you need to separate the functionality, and you're input will have to be text, not a nlohmann::basic_json
.
Thanks for the speedy response!
I guess I'll just read the input file separately with jsoncons
for the validation step for now then. Maybe in future I'll migrate to using jsoncons
everywhere else too.
I guess I'll just read the input file separately with
jsoncons
for the validation step
That would definitely be my recommendation, hide the validation code in a cpp file, provide a function interface that accepts text or a stream, and don't let jsoncons leak into the rest of your application.
I'm currently working on a project which uses the
nlohmann-json
library for JSON parsing. It seems like it could be possible to support this as a backend for the JSON schema module but it currently doesn't work: