22 unsigned long refcount;
25 #define json_typeof(json) ((json)->type)
26 #define json_is_object(json) (json && json_typeof(json) == JSON_OBJECT)
27 #define json_is_array(json) (json && json_typeof(json) == JSON_ARRAY)
28 #define json_is_string(json) (json && json_typeof(json) == JSON_STRING)
29 #define json_is_integer(json) (json && json_typeof(json) == JSON_INTEGER)
30 #define json_is_real(json) (json && json_typeof(json) == JSON_REAL)
31 #define json_is_number(json) (json_is_integer(json) || json_is_real(json))
32 #define json_is_true(json) (json && json_typeof(json) == JSON_TRUE)
33 #define json_is_false(json) (json && json_typeof(json) == JSON_FALSE)
34 #define json_is_null(json) (json && json_typeof(json) == JSON_NULL)
36 /* construction, destruction, reference counting */
38 json_t *json_object(void);
39 json_t *json_array(void);
40 json_t *json_string(const char *value);
41 json_t *json_integer(int value);
42 json_t *json_real(double value);
43 json_t *json_true(void);
44 json_t *json_false(void);
45 json_t *json_null(void);
47 json_t *json_clone(json_t *json);
49 static inline json_t *json_incref(json_t *json)
56 /* do not call json_delete directly */
57 void json_delete(json_t *json);
59 static inline void json_decref(json_t *json)
61 if(json && --json->refcount == 0)
66 /* getters, setters, manipulation */
68 json_t *json_object_get(const json_t *object, const char *key);
69 int json_object_set(json_t *object, const char *key, json_t *value);
70 int json_object_del(json_t *object, const char *key);
71 void *json_object_iter(json_t *object);
72 void *json_object_iter_next(json_t *object, void *iter);
73 const char *json_object_iter_key(void *iter);
74 json_t *json_object_iter_value(void *iter);
76 unsigned int json_array_size(const json_t *array);
77 json_t *json_array_get(const json_t *array, unsigned int index);
78 int json_array_set(json_t *array, unsigned int index, json_t *value);
79 int json_array_append(json_t *array, json_t *value);
81 const char *json_string_value(const json_t *json);
82 int json_integer_value(const json_t *json);
83 double json_real_value(const json_t *json);
84 double json_number_value(const json_t *json);
87 /* loading, printing */
89 #define JSON_ERROR_TEXT_LENGTH 160
92 char text[JSON_ERROR_TEXT_LENGTH];
96 json_t *json_loads(const char *input, json_error_t *error);
97 json_t *json_loadf(FILE *input, json_error_t *error);
98 json_t *json_load_file(const char *path, json_error_t *error);
100 #define JSON_INDENT(n) (n & 0xFF)
102 char *json_dumps(const json_t *json, uint32_t flags);
103 int json_dumpf(const json_t *json, FILE *output, uint32_t flags);
104 int json_dump_file(const json_t *json, const char *path, uint32_t flags);