2014-02-06 05:27:48 +00:00
|
|
|
typedef enum json_type {
|
2014-02-08 00:49:52 +00:00
|
|
|
// These types can be returned by json_read()
|
2015-06-03 18:21:40 +00:00
|
|
|
JSON_HASH,
|
|
|
|
JSON_ARRAY,
|
|
|
|
JSON_NUMBER,
|
|
|
|
JSON_STRING,
|
|
|
|
JSON_TRUE,
|
|
|
|
JSON_FALSE,
|
|
|
|
JSON_NULL,
|
2014-02-08 00:01:27 +00:00
|
|
|
|
2014-02-08 00:49:52 +00:00
|
|
|
// These and JSON_HASH and JSON_ARRAY can be called back by json_read_with_separators()
|
2015-06-03 18:21:40 +00:00
|
|
|
JSON_COMMA,
|
|
|
|
JSON_COLON,
|
2014-02-08 00:01:27 +00:00
|
|
|
|
|
|
|
// These are only used internally as expectations of what comes next
|
2015-06-03 18:21:40 +00:00
|
|
|
JSON_ITEM,
|
|
|
|
JSON_KEY,
|
|
|
|
JSON_VALUE,
|
2014-02-06 05:27:48 +00:00
|
|
|
} json_type;
|
|
|
|
|
|
|
|
typedef struct json_object {
|
|
|
|
json_type type;
|
|
|
|
struct json_object *parent;
|
|
|
|
|
|
|
|
char *string;
|
|
|
|
double number;
|
2014-02-06 07:18:27 +00:00
|
|
|
|
|
|
|
struct json_object **array;
|
|
|
|
struct json_object **keys;
|
|
|
|
struct json_object **values;
|
|
|
|
int length;
|
2014-02-07 02:56:22 +00:00
|
|
|
|
|
|
|
int expect;
|
2014-02-06 05:27:48 +00:00
|
|
|
} json_object;
|
|
|
|
|
2014-02-08 00:56:38 +00:00
|
|
|
typedef struct json_pull {
|
2014-02-07 02:56:22 +00:00
|
|
|
char *error;
|
2014-02-08 02:11:36 +00:00
|
|
|
int line;
|
2014-02-07 03:22:37 +00:00
|
|
|
|
2014-10-19 22:35:28 +00:00
|
|
|
int (*read)(struct json_pull *, char *buf, int n);
|
2014-02-07 03:22:37 +00:00
|
|
|
void *source;
|
2014-10-19 22:35:28 +00:00
|
|
|
char *buffer;
|
|
|
|
int buffer_tail;
|
|
|
|
int buffer_head;
|
2014-02-07 05:06:27 +00:00
|
|
|
|
|
|
|
json_object *container;
|
2014-02-08 17:30:02 +00:00
|
|
|
json_object *root;
|
2014-02-08 00:56:38 +00:00
|
|
|
} json_pull;
|
2014-02-07 23:51:46 +00:00
|
|
|
|
2014-02-07 03:22:37 +00:00
|
|
|
json_pull *json_begin_file(FILE *f);
|
2014-02-07 03:27:21 +00:00
|
|
|
json_pull *json_begin_string(char *s);
|
2014-10-19 22:35:28 +00:00
|
|
|
|
|
|
|
json_pull *json_begin(int (*read)(struct json_pull *, char *buffer, int n), void *source);
|
2014-02-08 00:56:38 +00:00
|
|
|
void json_end(json_pull *p);
|
|
|
|
|
|
|
|
typedef void (*json_separator_callback)(json_type type, json_pull *j, void *state);
|
2014-02-08 00:22:47 +00:00
|
|
|
|
2014-02-08 00:56:38 +00:00
|
|
|
json_object *json_read_tree(json_pull *j);
|
2014-02-08 00:49:52 +00:00
|
|
|
json_object *json_read(json_pull *j);
|
2014-02-08 02:01:18 +00:00
|
|
|
json_object *json_read_separators(json_pull *j, json_separator_callback cb, void *state);
|
2014-02-07 06:45:40 +00:00
|
|
|
void json_free(json_object *j);
|
2015-10-23 21:58:50 +00:00
|
|
|
void json_disconnect(json_object *j);
|
2014-02-07 02:56:22 +00:00
|
|
|
|
2014-12-02 22:17:49 +00:00
|
|
|
json_object *json_hash_get(json_object *o, const char *s);
|