diff options
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1,3 +1,29 @@ #pragma once +#include <json-c/json.h> + + #define NODE_NAME(c) (*(char **)&(c)->node.key) + + +static inline struct json_object * neco_json_get_value( + struct json_object *obj, + const char *key, + enum json_type type +) { + struct json_object *value; + if (!json_object_object_get_ex(obj, key, &value)) + return NULL; + if (!json_object_is_type(value, type)) + return NULL; + + return value; +} + +static inline const char * neco_json_get_string(struct json_object *obj, const char *key) { + struct json_object *value = neco_json_get_value(obj, key, json_type_string); + if (!value) + return NULL; + + return json_object_get_string(value); +} |