blob: 0cc43db3c3b3ea98400a90b77599bf4cdb6ef472 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_json.h Interface to JavaScript Object Notation (JSON) -- RFC 7159
3 *
4 * Copyright (C) 2010 - 2015 Creytiv.com
5 */
6
7enum json_typ {
8 JSON_STRING,
9 JSON_INT,
10 JSON_DOUBLE,
11 JSON_BOOL,
12 JSON_NULL,
13};
14
15struct json_value {
16 union {
17 char *str;
18 int64_t integer;
19 double dbl;
20 bool boolean;
21 } v;
22 enum json_typ type;
23};
24
25struct json_handlers;
26
27typedef int (json_object_entry_h)(const char *name,
28 const struct json_value *value, void *arg);
29typedef int (json_array_entry_h)(unsigned idx,
30 const struct json_value *value, void *arg);
31typedef int (json_object_h)(const char *name, unsigned idx,
32 struct json_handlers *h);
33typedef int (json_array_h)(const char *name, unsigned idx,
34 struct json_handlers *h);
35
36struct json_handlers {
37 json_object_h *oh;
38 json_array_h *ah;
39 json_object_entry_h *oeh;
40 json_array_entry_h *aeh;
41 void *arg;
42};
43
44int json_decode(const char *str, size_t len, unsigned maxdepth,
45 json_object_h *oh, json_array_h *ah,
46 json_object_entry_h *oeh, json_array_entry_h *aeh, void *arg);
47
48int json_decode_odict(struct odict **op, uint32_t hash_size, const char *str,
49 size_t len, unsigned maxdepth);
50int json_encode_odict(struct re_printf *pf, const struct odict *o);