Start validating json
Make sure json matches the schema, or don't load the file.
Also start installing json files using CMakeLists instead of
in the recipe.
Change-Id: I78622b961d1185d864d6ddd27e5baad34bc3ef5e
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/Utils.cpp b/src/Utils.cpp
index b5c3787..6db1157 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -18,6 +18,10 @@
#include <experimental/filesystem>
#include <fstream>
#include <regex>
+#include <valijson/adapters/nlohmann_json_adapter.hpp>
+#include <valijson/schema.hpp>
+#include <valijson/schema_parser.hpp>
+#include <valijson/validator.hpp>
namespace fs = std::experimental::filesystem;
@@ -45,4 +49,19 @@
}
}
return true;
+}
+
+bool validateJson(const nlohmann::json &schemaFile, const nlohmann::json &input)
+{
+ valijson::Schema schema;
+ valijson::SchemaParser parser;
+ valijson::adapters::NlohmannJsonAdapter schemaAdapter(schemaFile);
+ parser.populateSchema(schemaAdapter, schema);
+ valijson::Validator validator;
+ valijson::adapters::NlohmannJsonAdapter targetAdapter(input);
+ if (!validator.validate(schema, targetAdapter, NULL))
+ {
+ return false;
+ }
+ return true;
}
\ No newline at end of file