diff --git a/src/ConvertInputFormat/main.cpp b/src/ConvertInputFormat/main.cpp index f8c37a45b44..ba9f38518f5 100644 --- a/src/ConvertInputFormat/main.cpp +++ b/src/ConvertInputFormat/main.cpp @@ -69,7 +69,7 @@ #include #include -using json = nlohmann::json; +using json = nlohmann::ordered_json; enum class OutputTypes { @@ -294,7 +294,8 @@ bool processInput(fs::path const &inputFilePath, OutputTypes outputType, fs::path outputDirPath, std::string &outputTypeStr, - bool convertHVACTemplate) + bool convertHVACTemplate, + bool orderJSON) { auto validation(std::make_unique(&schema)); auto idf_parser(std::make_unique()); @@ -502,6 +503,9 @@ Select one (case insensitive): bool noConvertHVACTemplate = false; app.add_flag("-n,--noHVACTemplate", noConvertHVACTemplate, "Do not convert HVACTemplate objects"); + bool orderJSON = false; + app.add_flag("-k,--orderJSON", orderJSON, "Order epJSON objects"); + std::vector files; app.add_option("input_file", files, "Multiple input files to be translated")->required(false)->check(CLI::ExistingFile); @@ -554,7 +558,7 @@ Select one (case insensitive): { # pragma omp for for (int i = 0; i < number_files; ++i) { - const bool successful = processInput(files[i], schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate); + const bool successful = processInput(files[i], schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate, orderJSON); # pragma omp atomic ++fileCount; if (successful) { @@ -573,7 +577,7 @@ Select one (case insensitive): } for (auto const &file : files) { - bool successful = processInput(file, schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate); + bool successful = processInput(file, schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate, orderJSON); ++fileCount; if (successful) { displayMessage("Input file converted to {} successfully | {}/{} | {}", outputTypeStr, fileCount, number_files, file.generic_string()); diff --git a/src/EnergyPlus/FileSystem.cc b/src/EnergyPlus/FileSystem.cc index 8b74c535a30..b25ee5e4bd2 100644 --- a/src/EnergyPlus/FileSystem.cc +++ b/src/EnergyPlus/FileSystem.cc @@ -366,7 +366,7 @@ namespace FileSystem { return result; } - nlohmann::json readJSON(fs::path const &filePath, std::ios_base::openmode mode) + nlohmann::ordered_json readJSON(fs::path const &filePath, std::ios_base::openmode mode) { // Shenanigans would not be needed with fmt 10+ (maybe earlier), because fmt has native fs::path support @@ -389,15 +389,15 @@ namespace FileSystem { case FileTypes::EpJSON: case FileTypes::JSON: case FileTypes::GLHE: - return nlohmann::json::parse(file, nullptr, true, true); + return nlohmann::ordered_json::parse(file, nullptr, true, true); case FileTypes::CBOR: - return nlohmann::json::from_cbor(file); + return nlohmann::ordered_json::from_cbor(file); case FileTypes::MsgPack: - return nlohmann::json::from_msgpack(file); + return nlohmann::ordered_json::from_msgpack(file); case FileTypes::UBJSON: - return nlohmann::json::from_ubjson(file); + return nlohmann::ordered_json::from_ubjson(file); case FileTypes::BSON: - return nlohmann::json::from_bson(file); + return nlohmann::ordered_json::from_bson(file); default: throw FatalError("Invalid file extension. Must be epJSON, JSON, or other experimental extensions"); } diff --git a/src/EnergyPlus/FileSystem.hh b/src/EnergyPlus/FileSystem.hh index edd806a8897..6d297b3afc6 100644 --- a/src/EnergyPlus/FileSystem.hh +++ b/src/EnergyPlus/FileSystem.hh @@ -192,22 +192,22 @@ namespace FileSystem { std::string readFile(fs::path const &filePath, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary); // Reads the full json file if it exists - nlohmann::json readJSON(fs::path const &filePath, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary); + nlohmann::ordered_json readJSON(fs::path const &filePath, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary); - template std::string getJSON(const nlohmann::json &data, int const indent = 4) + template std::string getJSON(const nlohmann::ordered_json &data, int const indent = 4) { if constexpr (is_json_type(fileType)) { - return data.dump(indent, ' ', false, nlohmann::json::error_handler_t::replace); + return data.dump(indent, ' ', false, nlohmann::ordered_json::error_handler_t::replace); } else if constexpr (is_binary_json_type(fileType)) { std::string binary_data; if constexpr (fileType == FileTypes::CBOR) { - nlohmann::json::to_cbor(data, binary_data); + nlohmann::ordered_json::to_cbor(data, binary_data); } else if constexpr (fileType == FileTypes::MsgPack) { - nlohmann::json::to_msgpack(data, binary_data); + nlohmann::ordered_json::to_msgpack(data, binary_data); } else if constexpr (fileType == FileTypes::BSON) { - nlohmann::json::to_bson(data, binary_data); + nlohmann::ordered_json::to_bson(data, binary_data); } else if constexpr (fileType == FileTypes::UBJSON) { - nlohmann::json::to_ubjson(data, binary_data); + nlohmann::ordered_json::to_ubjson(data, binary_data); } return binary_data; } else { @@ -225,7 +225,7 @@ namespace FileSystem { template inline constexpr bool enable_json_v = - is_all_json_type(fileType) && is_any::value && !is_any::value; + is_all_json_type(fileType) && is_any::value && !is_any::value; template void writeFile(fs::path const &filePath, const std::string_view data) { diff --git a/src/EnergyPlus/InputProcessing/IdfParser.cc b/src/EnergyPlus/InputProcessing/IdfParser.cc index fa3e989f094..81e382de951 100644 --- a/src/EnergyPlus/InputProcessing/IdfParser.cc +++ b/src/EnergyPlus/InputProcessing/IdfParser.cc @@ -53,7 +53,7 @@ #include #include -using json = nlohmann::json; +using json = nlohmann::ordered_json; auto const icompare = [](std::string_view a, std::string_view b) { // (AUTO_OK) return (a.length() == b.length() diff --git a/src/EnergyPlus/InputProcessing/IdfParser.hh b/src/EnergyPlus/InputProcessing/IdfParser.hh index 5a6024983a7..7b0c84eccf4 100644 --- a/src/EnergyPlus/InputProcessing/IdfParser.hh +++ b/src/EnergyPlus/InputProcessing/IdfParser.hh @@ -61,7 +61,7 @@ class IdfParser { public: friend class EnergyPlus::InputProcessorFixture; - using json = nlohmann::json; + using json = nlohmann::ordered_json; IdfParser() = default; diff --git a/src/EnergyPlus/InputProcessing/InputProcessor.cc b/src/EnergyPlus/InputProcessing/InputProcessor.cc index 399de684216..7186416877f 100644 --- a/src/EnergyPlus/InputProcessing/InputProcessor.cc +++ b/src/EnergyPlus/InputProcessing/InputProcessor.cc @@ -102,7 +102,7 @@ namespace EnergyPlus { static std::string const BlankString; -using json = nlohmann::json; +using json = nlohmann::ordered_json; const json &InputProcessor::schema() { diff --git a/src/EnergyPlus/InputProcessing/InputProcessor.hh b/src/EnergyPlus/InputProcessing/InputProcessor.hh index ebabb297d6c..30cfd2b99dd 100644 --- a/src/EnergyPlus/InputProcessing/InputProcessor.hh +++ b/src/EnergyPlus/InputProcessing/InputProcessor.hh @@ -76,12 +76,12 @@ struct EnergyPlusData; namespace EnergyPlus { -void cleanEPJSON(nlohmann::json &epjson); +void cleanEPJSON(nlohmann::ordered_json &epjson); class InputProcessor { public: - using json = nlohmann::json; + using json = nlohmann::ordered_json; json::parser_callback_t callback; diff --git a/src/EnergyPlus/InputProcessing/InputValidation.cc b/src/EnergyPlus/InputProcessing/InputValidation.cc index d41e85346b1..8feb5b25e03 100644 --- a/src/EnergyPlus/InputProcessing/InputValidation.cc +++ b/src/EnergyPlus/InputProcessing/InputValidation.cc @@ -57,7 +57,7 @@ #include #include -using json = nlohmann::json; +using json = nlohmann::ordered_json; Validation::Validation(json const *parsed_schema) { diff --git a/src/EnergyPlus/InputProcessing/InputValidation.hh b/src/EnergyPlus/InputProcessing/InputValidation.hh index 92172a6a34b..2b9b0bbcd99 100644 --- a/src/EnergyPlus/InputProcessing/InputValidation.hh +++ b/src/EnergyPlus/InputProcessing/InputValidation.hh @@ -58,7 +58,7 @@ class Validation { public: - using json = nlohmann::json; + using json = nlohmann::ordered_json; explicit Validation(json const *parsed_schema); diff --git a/src/EnergyPlus/ResultsFramework.hh b/src/EnergyPlus/ResultsFramework.hh index 8b8a1a8ef19..3dc90704ae8 100644 --- a/src/EnergyPlus/ResultsFramework.hh +++ b/src/EnergyPlus/ResultsFramework.hh @@ -73,7 +73,7 @@ struct JsonOutputFilePaths; namespace ResultsFramework { - using json = nlohmann::json; + using json = nlohmann::ordered_json; using OutputProcessor::ReportFreq; using OutputProcessor::TimeStepType; diff --git a/tst/EnergyPlus/unit/Fixtures/EnergyPlusFixture.cc b/tst/EnergyPlus/unit/Fixtures/EnergyPlusFixture.cc index 714aba13047..ba89681148e 100644 --- a/tst/EnergyPlus/unit/Fixtures/EnergyPlusFixture.cc +++ b/tst/EnergyPlus/unit/Fixtures/EnergyPlusFixture.cc @@ -70,7 +70,7 @@ #include #include -using json = nlohmann::json; +using json = nlohmann::ordered_json; namespace EnergyPlus { diff --git a/tst/EnergyPlus/unit/Fixtures/InputProcessorFixture.hh b/tst/EnergyPlus/unit/Fixtures/InputProcessorFixture.hh index ea1591d6d3d..a9e5c0efbf4 100644 --- a/tst/EnergyPlus/unit/Fixtures/InputProcessorFixture.hh +++ b/tst/EnergyPlus/unit/Fixtures/InputProcessorFixture.hh @@ -62,7 +62,7 @@ namespace EnergyPlus { class InputProcessorFixture : public EnergyPlusFixture { protected: - using json = nlohmann::json; + using json = nlohmann::ordered_json; // static void SetUpTestCase() // { diff --git a/tst/EnergyPlus/unit/Fixtures/ResultsFrameworkFixture.hh b/tst/EnergyPlus/unit/Fixtures/ResultsFrameworkFixture.hh index e4613567808..3ebba4ead52 100644 --- a/tst/EnergyPlus/unit/Fixtures/ResultsFrameworkFixture.hh +++ b/tst/EnergyPlus/unit/Fixtures/ResultsFrameworkFixture.hh @@ -60,7 +60,7 @@ namespace EnergyPlus { class ResultsFrameworkFixture : public EnergyPlusFixture { protected: - using json = nlohmann::json; + using json = nlohmann::ordered_json; // static void SetUpTestCase() // {