aboutsummaryrefslogtreecommitdiff
path: root/src/json/json.h
blob: 15b3fca843b7ec305123ee7de666b1d087370eaa (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

#pragma once
#include "../std/memory.h"
#include "../std/str.h"
#include "../std/vec.h"

typedef struct {
    Vec keys;   // Vec<Str>
    Vec values; // Vec<JSON>
    size len;
} JSONObject;
typedef enum {
    JSON_NULL,
    JSON_BOOL,
    JSON_INTEGER,
    JSON_FLOAT,
    JSON_STRING,
    JSON_ARRAY,
    JSON_OBJECT
} JSONType;
typedef struct {
    JSONType type;
    union {
        bool boolean;
        i32 integer;
        f32 floating;
        Vec array; // Vec<JSON>
        StrView string;
        JSONObject object;
    } as;
} JSON;
JSON *JSONObject_get(JSONObject obj, Str key);
i32 JSON_fprint(FILE *w, JSON json);
JSON JSON_parse(Arena *a, byte *src, uptr len);
JSON JSON_Int(Arena *a, i32 val);