Search code examples
jsonqtschema

What support is there for json schema in Qt / C++ / C


Qt support for XML is very strong, up to and including support for XML schema validation.

Qt Support for JSON appears to be less extensive. Nothing I can find seems to confirm or deny support for json-schema or any other kind of Json schema validation in Qt.

Is there a sound way to validate json in Qt / C++?

Edit: to be clear, this question is centered on Json schema validation, not just confirming if an arbitrary document is valid Json.


Solution

  • Indeed, it seems there are no Qt support for JSON Schema validation, even in Qt 5.1. Since writing your own would be very time-consuming, I would suggest:

    • If you as developer would have provided the Schema, then do not validate by using a JSON Schema validation, but instead perform a hard-coded validation of your parsed JSON (i.e., manually check that the required fields are present, are of the correct type, and are within the specified bounds)

    • If handling external JSON Schema is necessary (i.e., the Schema is not known in advance, possibly user-defined), then do not use Qt but an independent C/C++ JSON validator, like WJElement (the one linked on the json-schema website)