#include "JsonUtilities.h"

#include <iostream>
#include <nlohmann/json.hpp>
#include <string>


json MergeJsonObjects(const json& json1, const json& json2) {
    json mergedJson = json1;  // Start with the first JSON object

    // Iterate over the second JSON and insert or overwrite keys in mergedJson
    for (auto it = json2.begin(); it != json2.end(); ++it) {
        mergedJson[it.key()] = it.value();
    }

    return mergedJson;
}

json ConvertStringToJson(const std::string& input_string) {
    try {
        return json::parse(input_string);
    }
    catch (const nlohmann::json::parse_error& e) {
        // Handle parsing errors, e.g., malformed JSON string.
        // Output the exception message as a std::string.
        std::string errorMsg = e.what();
        std::cout << errorMsg << std::endl;
        return nullptr;
    }
}