2 #include "blobmsg_json.h"
4 static bool blobmsg_add_object(struct blob_buf *b, json_object *obj)
6 json_object_object_foreach(obj, key, val) {
7 if (!blobmsg_add_json_element(b, key, val))
13 static bool blobmsg_add_array(struct blob_buf *b, struct array_list *a)
17 for (i = 0, len = array_list_length(a); i < len; i++) {
18 if (!blobmsg_add_json_element(b, NULL, array_list_get_idx(a, i)))
25 bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object *obj)
33 switch (json_object_get_type(obj)) {
34 case json_type_object:
35 c = blobmsg_open_table(b, name);
36 ret = blobmsg_add_object(b, obj);
37 blobmsg_close_table(b, c);
40 c = blobmsg_open_array(b, name);
41 ret = blobmsg_add_array(b, json_object_get_array(obj));
42 blobmsg_close_array(b, c);
44 case json_type_string:
45 blobmsg_add_string(b, name, json_object_get_string(obj));
47 case json_type_boolean:
48 blobmsg_add_u8(b, name, json_object_get_boolean(obj));
51 blobmsg_add_u32(b, name, json_object_get_int(obj));
59 bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str)
64 obj = json_tokener_parse(str);
68 if (json_object_get_type(obj) != json_type_object)
71 ret = blobmsg_add_object(b, obj);