diff --git a/framework/filesystem/src/mm/services/filesystem.cpp b/framework/filesystem/src/mm/services/filesystem.cpp index 17e3c94..8e66585 100644 --- a/framework/filesystem/src/mm/services/filesystem.cpp +++ b/framework/filesystem/src/mm/services/filesystem.cpp @@ -316,6 +316,31 @@ nlohmann::json FilesystemService::readJson(const char* filepath) const { return r; } +nlohmann::ordered_json FilesystemService::readJsonOrdered(fs_file_t file) const { + if (!file) + return {}; + + seek(file, 0); + + std::string buffer; + readString(file, buffer); + + // disable exeptions + // TODO: use callback instead of readString() + return nlohmann::ordered_json::parse(buffer, nullptr, false); +} + +nlohmann::ordered_json FilesystemService::readJsonOrdered(const char* filepath) const { + if (!isFile(filepath)) { + return {}; + } + + auto h = open(filepath, READ); + auto r = readJsonOrdered(h); + close(h); + return r; +} + bool FilesystemService::writeJson(fs_file_t file, nlohmann::json& j, const int indent, const char indent_char) const { if (!file) { LOG_ERROR("writing json to invalid file"); diff --git a/framework/filesystem/src/mm/services/filesystem.hpp b/framework/filesystem/src/mm/services/filesystem.hpp index cf55652..c9cd95b 100644 --- a/framework/filesystem/src/mm/services/filesystem.hpp +++ b/framework/filesystem/src/mm/services/filesystem.hpp @@ -78,6 +78,9 @@ class FilesystemService : public Service { nlohmann::json readJson(fs_file_t file) const; nlohmann::json readJson(const char* filepath) const; + nlohmann::ordered_json readJsonOrdered(fs_file_t file) const; + nlohmann::ordered_json readJsonOrdered(const char* filepath) const; + bool writeJson(fs_file_t file, nlohmann::json& j, const int indent = -1, const char indent_char = ' ') const; bool writeJson(const char* filepath, nlohmann::json& j, const int indent = -1, const char indent_char = ' ') const;