blob: 082e04fde61a27bcaa0d235ed3f61e0d188ea28f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#ifndef NET_JSON_H
#define NET_JSON_H
// NOTE: tiny recursive descent json parser. the whole tree lives in the arena, strings point
// into the source buffer unless they had escapes, then they're unescaped into the arena.
typedef enum JsonKind {
JSON_NULL,
JSON_BOOL,
JSON_NUMBER,
JSON_STRING,
JSON_ARRAY,
JSON_OBJECT,
} JsonKind;
typedef struct JsonValue JsonValue;
struct JsonValue {
JsonKind kind;
b32 boolean;
f64 number;
String8 string;
String8 key; // set when this value is an object member
JsonValue *first; // children of arrays/objects
JsonValue *next; // next sibling
u32 count;
};
internal JsonValue *json_parse(Arena *arena, String8 text);
internal JsonValue *json_get(JsonValue *object, const char *key);
internal String8 json_get_string(JsonValue *object, const char *key);
internal f64 json_get_number(JsonValue *object, const char *key);
#define FOR_JSON_CHILD(parent, child) for(JsonValue *child = (parent) ? (parent)->first : 0; child; child = child->next)
#endif // NET_JSON_H
|