#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