summaryrefslogtreecommitdiffstats
path: root/src/util.h
blob: 2e6046734a7c62fe3873da61c3de7307f393859e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
}