How to get the key name from a JSON::Value variable using jsoncpp in c++?

Viewed 38

I am loading my program config at the program start from a json file. To make sure, that the file contains every requested key, I am checking every json key and return its existence to a bool variable "config_is_valid". If one key is missing and my boolean switches to false, I display an error message and stop the program execution.

How can I get the json key from the passed variable "param" inside my check_config_value(...) function? I want to print the missing keyname to the console without touching my caller function, because I have like hundred values and dont want to validate the return value from the check_config_value() function each time.

bool config_is_valid = true;

VARIABLES::config::first_config_value = check_config_value(system_config["first_layer"]["keyname_i_want_to_know"], config_is_valid).asBool();
VARIABLES::config.....


Json::Value check_config_value(Json::Value param, bool& validity)
{

    if (param == Json::Value::null)
    {
        validity = false;
    }

    return param;
}
0 Answers
Related