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

Qt support for XML is very strong, down to supporting XML schema validation.

Qt JSON support seems less extensive. Nothing I can find seems to confirm or deny json-schema support or any other kind of Json schema check in Qt,

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

Edit: In order to be clear, this question focuses on checking the Json schema , not just confirming whether an arbitrary document is valid Json.

+4
source share
4 answers

Indeed, it seems that Qt support for checking JSON Schema does not exist, even in Qt 5.1. Since writing your own would be very time consuming, I would suggest:

  • If you, as a developer, provided a scheme, then do not check with the JSON Schema check, but instead perform a strictly coded check of your JSON parsing (i.e. manually check for the necessary fields, are of the correct type and are within the specified boundaries)

  • If processing of an external JSON scheme is required (i.e. the scheme is not known in advance, possibly user-defined), then do not use Qt, but an independent JSON C / C ++ validator, for example WJElement (the one specified on the json- website schema)

+2
source

Qt 5.8 still does not have JSON Schema validation ... But you can find a bunch of other interesting libraries.

The 4 C / C ++ libraries are listed on the JSON Schema website:

  • wjelement mentioned by @Boris is optimized for performance and is used in the Messaging Architects email creation environment. This is a C library, but the C ++ shell ( wjelement-cpp ) is also available.
  • valijson is a header-only schema checker that can be used with another JSON parser.
  • The json-schema-validator is based on nlohmann modern C ++ JSON parser , which have nice features like good interaction with STL containers. But this validator looks less mature.

Other JSON Schema Validator validation projects can be found on github or bitbucket, including:

  • jv_json dedicated to embedded applications.
  • libvariant , which can also handle YAML and PLIST formats.
+1
source

It exists at http://qjson.sourceforge.net/ , which also does not include schema validation.

It also exists Qtjsonstream in qtplayground, which includes some schema checking, but I do not use it, so I do not know anything else about it.

0
source

I offer you yse qt-json , it has simple vlidation, as valid or not.

bool ok; QtJson::JsonObject result = QtJson::parse(json, ok).toMap(); 
-one
source

Source: https://habr.com/ru/post/1500624/


All Articles