20 #include "jsonparser.h" 26 if (!
hasKey(element, key)) {
30 return read(element, key, result);
35 if (!
hasKey(element, key)) {
39 return read(element, key, result);
44 if (!
hasKey(element, key)) {
48 return read(element, key, result);
53 json_t *value = json_object_get(element, key);
55 log_warning() <<
"Could not fetch \"" << key <<
"\" from json element";
59 if (!json_is_string(value)) {
60 log_error() <<
"json element is not a string";
64 result = json_string_value(value);
70 json_t *value = json_object_get(element, key);
72 log_warning() <<
"Could not fetch \"" << key <<
"\" from json element";
76 if (!json_is_boolean(value)) {
77 log_error() <<
"json element is not a boolean";
81 result = json_is_true(value);
87 json_t *value = json_object_get(element, key);
89 log_warning() <<
"Could not fetch \"" << key <<
"\" from json element";
93 if (!json_is_integer(value)) {
94 log_error() <<
"json element is not an integer";
98 result = json_integer_value(value);
104 return json_object_get(element, key) != NULL;
static bool readOptional(const json_t *element, const char *key, std::string &result)
Reads an optional value from a JSON object.
static bool hasKey(const json_t *element, const char *key)
Checks if a given JSON object contains a certain key.
Developers guide to adding a config item:
static bool read(const json_t *element, const char *key, std::string &result)
Reads a string from a JSON Object.