Testing building json objects in C

This commit is contained in:
2023-06-25 23:52:45 +01:00
parent c4caa1bb84
commit 3ded1d2708
3 changed files with 62 additions and 14 deletions

51
include/json_test.h Normal file
View File

@@ -0,0 +1,51 @@
#ifndef JSON_TEST_H
#define JSON_TEST_H
#include "aliases.h"
#include <stdbool.h>
typedef struct json_obj_pair jobj_pair_t;
typedef struct json_coll jcoll_t;
typedef struct json_val jval_t;
typedef enum {
JSON_OBJECT,
JSON_ARRAY,
} jcoll_type_t;
typedef enum {
JSON_COLLECTION,
JSON_STRING,
JSON_INTEGER,
JSON_DOUBLE,
JSON_TRUE,
JSON_FALSE,
JSON_NULL,
} jval_type_t;
struct json_val {
jval_type_t type;
union {
jcoll_t *collection;
const char *string;
i64 num_int;
f64 num_dbl;
bool boolean;
};
};
struct json_obj_pair {
const char *key;
jval_t value;
};
struct json_coll {
jcoll_type_t type;
u64 size;
union {
jobj_pair_t pairs[50];
jval_t items[50];
};
};
#endif // !JSON_TEST_H