mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-25 20:16:14 -05:00
[misc] Add json_drilldown() function
Will descend into a json object along the path set by a list of keys
This commit is contained in:
@@ -32,6 +32,29 @@
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
json_object *
|
||||
jparse_drilldown(json_object *haystack, const char *keys[])
|
||||
{
|
||||
json_object *needle;
|
||||
json_bool found;
|
||||
|
||||
while (*keys)
|
||||
{
|
||||
found = json_object_object_get_ex(haystack, *keys, &needle);
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
if (json_object_get_type(needle) == json_type_array)
|
||||
haystack = json_object_array_get_idx(needle, 0);
|
||||
else
|
||||
haystack = needle;
|
||||
|
||||
keys++;
|
||||
}
|
||||
|
||||
return needle;
|
||||
}
|
||||
|
||||
void
|
||||
jparse_free(json_object* haystack)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user