aboutsummaryrefslogtreecommitdiff
path: root/include/json.h
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-23 19:39:13 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-23 19:39:26 +0200
commit421300c27123ca647772dc6d9bd0cabf7f5f9c99 (patch)
treed916b62056b2440aef374b21373d16272bb709ee /include/json.h
parent53e9e371a16ae2d167f1fc2577dff2c2426eed68 (diff)
refactor: src & pragma once
Diffstat (limited to 'include/json.h')
-rw-r--r--include/json.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/json.h b/include/json.h
new file mode 100644
index 0000000..749a3e0
--- /dev/null
+++ b/include/json.h
@@ -0,0 +1,34 @@
+#pragma once
+#include "../include/memory.h"
+#include "../include/str.h"
+#include "../include/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>
+ Str 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);
+JSON JSON_Int(Arena *a, i32 val);