* \brief Utility function to create a rapidjson::Document object from a file path * * \jsonfile is the file path of the json data * * \returns rapidjson::Document object representing the json file * \throws std::runtime_error if the input file is non-existent or is not a valid json file */
| 43 | * \throws std::runtime_error if the input file is non-existent or is not a valid json file |
| 44 | */ |
| 45 | rapidjson::Document |
| 46 | ReadJSONDocument(std::string const& filePath) |
| 47 | { |
| 48 | std::ifstream fileStream(filePath.c_str()); |
| 49 | if (!fileStream.is_open()) |
| 50 | { |
| 51 | throw std::runtime_error("Failed to open file at " + filePath); |
| 52 | } |
| 53 | rapidjson::IStreamWrapper streamWrapper(fileStream); |
| 54 | rapidjson::Document doc; |
| 55 | doc.ParseStream(streamWrapper); |
| 56 | if (doc.HasParseError()) |
| 57 | { |
| 58 | throw std::runtime_error("File '" + filePath + "' is not a valid JSON\n Error(offset " |
| 59 | + std::to_string(doc.GetErrorOffset()) |
| 60 | + "): " + GetParseError_En(doc.GetParseError())); |
| 61 | } |
| 62 | return doc; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * \brief Function to validate json file against a schema file |