Class JsonArchive¶
Defined in File json_archive.h
Inheritance Relationships¶
Base Type¶
public portal::ArchiveObject(Class ArchiveObject)
Class Documentation¶
-
class JsonArchive : public portal::ArchiveObject¶
JSON format implementation of ArchiveObject for human-readable serialization.
JsonArchive provides JSON serialization/deserialization by converting the intermediate ArchiveObject property tree into nlohmann::json format. This enables human-readable, editable configuration files, saved games, resource metadata, and data exchange with external tools.
Public Functions
-
void dump(const std::filesystem::path &output_path, size_t indent = 4)¶
Serializes the ArchiveObject property tree to a JSON file.
Converts the internal ArchiveObject representation to nlohmann::json format and writes it to the specified file. File I/O errors are logged but don’t throw exceptions.
- Parameters:
output_path – Path to the output JSON file (created/overwritten)
indent – Number of spaces for indentation (4 = pretty-printed, 0 = compact)
-
void dump(std::ostream &output, size_t indent = 4)¶
Serializes the ArchiveObject property tree to an output stream in JSON format.
Converts the internal ArchiveObject representation to nlohmann::json and writes it to the provided stream with the specified indentation.
- Parameters:
output – The output stream to write JSON data to
indent – Number of spaces for indentation (4 = pretty-printed, 0 = compact)
-
void read(const std::filesystem::path &input_path)¶
Deserializes JSON content from a file into this ArchiveObject.
Parses the JSON file using nlohmann::json and populates this ArchiveObject’s property map with the parsed data. Parse errors and file I/O errors are logged to “Json Archive” tag.
- Parameters:
input_path – Path to the input JSON file to read and parse
-
void read(std::istream &input)¶
Deserializes JSON content from an input stream into this ArchiveObject.
Parses JSON from the stream and populates this ArchiveObject’s property map. Parse errors are logged but don’t throw exceptions.
- Parameters:
input – The input stream containing JSON data to parse
Protected Functions
-
nlohmann::json prepare_json()¶
-
void deserialize(const nlohmann::json &input)¶
-
void deserialize_object(ArchiveObject *root, const nlohmann::json &input)¶
-
void deserialize_array(ArchiveObject *root, const std::string &key, const nlohmann::json &array)¶
Protected Static Functions
-
static nlohmann::json prepare_object(ArchiveObject *object)¶
-
void dump(const std::filesystem::path &output_path, size_t indent = 4)¶