[misc] Add helper function to check if a key with a given type exists

This commit is contained in:
chme 2018-02-11 10:26:27 +01:00
parent 1379ef235c
commit 83bb06225b
2 changed files with 11 additions and 0 deletions

View File

@ -46,6 +46,14 @@ jparse_free(json_object* haystack)
} }
} }
bool
jparse_contains_key(json_object *haystack, const char *key, json_type type)
{
json_object *needle;
return json_object_object_get_ex(haystack, key, &needle) && json_object_get_type(needle) == type;
}
int int
jparse_array_from_obj(json_object *haystack, const char *key, json_object **needle) jparse_array_from_obj(json_object *haystack, const char *key, json_object **needle)
{ {

View File

@ -36,6 +36,9 @@
void void
jparse_free(json_object *haystack); jparse_free(json_object *haystack);
bool
jparse_contains_key(json_object *haystack, const char *key, json_type type);
int int
jparse_array_from_obj(json_object *haystack, const char *key, json_object **needle); jparse_array_from_obj(json_object *haystack, const char *key, json_object **needle);