u/json: Add bool getter function

This commit is contained in:
Jakob Bornecrantz 2020-04-06 11:17:50 +01:00 committed by Jakob Bornecrantz
parent b5dd07f2fa
commit f47c384b79
3 changed files with 26 additions and 0 deletions

View file

@ -0,0 +1 @@
u/json: Add bool getter function.

View file

@ -46,6 +46,23 @@ u_json_get_string_into_array(const cJSON *json, char *out_str, size_t max_size)
}
}
bool
u_json_get_bool(const cJSON *json, bool *out_bool)
{
assert(out_bool != NULL);
if (!json) {
return false;
}
if (!cJSON_IsBool(json)) {
return false;
}
*out_bool = json->valueint;
return true;
}
bool
u_json_get_int(const cJSON *json, int *out_int)
{

View file

@ -30,6 +30,14 @@ extern "C" {
bool
u_json_get_string_into_array(const cJSON *json, char *out, size_t max_size);
/*!
* @brief Parse an bool from a JSON object.
*
* @return true if successful, false if not.
*/
bool
u_json_get_bool(const cJSON *json, bool *out_bool);
/*!
* @brief Parse an int from a JSON object.
*