4 #include "lib/output_buffer.h"
10 #define JSON_TYPE_STRING 0
11 #define JSON_TYPE_INTEGER 1
12 #define JSON_TYPE_FLOAT 2
13 #define JSON_TYPE_OBJECT 3
14 #define JSON_TYPE_ARRAY 4
15 #define JSON_PARENT_TYPE_PAIR 0
16 #define JSON_PARENT_TYPE_ARRAY 1
20 long long integer_number;
23 struct json_object *object;
24 struct json_array *array;
28 struct json_pair *parent_pair;
29 struct json_array *parent_array;
34 struct json_value **values;
36 struct json_value *parent;
40 struct json_pair **pairs;
42 struct json_value *parent;
47 struct json_value *value;
48 struct json_object *parent;
51 struct json_object *json_create_object(void);
52 struct json_array *json_create_array(void);
54 void json_free_object(struct json_object *obj);
56 int json_object_add_value_type(struct json_object *obj, const char *name, int type, ...);
57 #define json_object_add_value_int(obj, name, val) \
58 json_object_add_value_type((obj), name, JSON_TYPE_INTEGER, (long long) (val))
59 #define json_object_add_value_float(obj, name, val) \
60 json_object_add_value_type((obj), name, JSON_TYPE_FLOAT, (val))
61 #define json_object_add_value_string(obj, name, val) \
62 json_object_add_value_type((obj), name, JSON_TYPE_STRING, (val))
63 #define json_object_add_value_object(obj, name, val) \
64 json_object_add_value_type((obj), name, JSON_TYPE_OBJECT, (val))
65 #define json_object_add_value_array(obj, name, val) \
66 json_object_add_value_type((obj), name, JSON_TYPE_ARRAY, (val))
67 int json_array_add_value_type(struct json_array *array, int type, ...);
68 #define json_array_add_value_int(obj, val) \
69 json_array_add_value_type((obj), JSON_TYPE_INTEGER, (val))
70 #define json_array_add_value_float(obj, val) \
71 json_array_add_value_type((obj), JSON_TYPE_FLOAT, (val))
72 #define json_array_add_value_string(obj, val) \
73 json_array_add_value_type((obj), JSON_TYPE_STRING, (val))
74 #define json_array_add_value_object(obj, val) \
75 json_array_add_value_type((obj), JSON_TYPE_OBJECT, (val))
76 #define json_array_add_value_array(obj, val) \
77 json_array_add_value_type((obj), JSON_TYPE_ARRAY, (val))
79 #define json_array_last_value_object(obj) \
80 (obj->values[obj->value_cnt - 1]->object)
82 void json_print_object(struct json_object *obj, struct buf_output *out);