41 lines
783 B
C
41 lines
783 B
C
|
#ifndef __JSON_H_
|
||
|
#define __JSON_H_
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
#include "util.h"
|
||
|
|
||
|
typedef enum {
|
||
|
JSON_OBJECT,
|
||
|
JSON_ARRAY,
|
||
|
JSON_STRING,
|
||
|
JSON_INT,
|
||
|
JSON_BOOL,
|
||
|
JSON_NULL,
|
||
|
} jsontype_t;
|
||
|
|
||
|
typedef struct jsonval {
|
||
|
jsontype_t type;
|
||
|
void *data;
|
||
|
} jsonval_t;
|
||
|
|
||
|
typedef struct {
|
||
|
const char *key;
|
||
|
jsonval_t val;
|
||
|
} jsonkv_t;
|
||
|
|
||
|
dynarr_def(jsonval_t, jsonval_dynarr_t);
|
||
|
dynarr_def(jsonkv_t, jsonkv_dynarr_t);
|
||
|
|
||
|
jsonval_t json_createobj(jsonkv_dynarr_t pairs);
|
||
|
jsonval_t json_createarr(jsonval_dynarr_t elems);
|
||
|
jsonval_t json_createstr(const char *str);
|
||
|
jsonval_t json_createint(long num);
|
||
|
jsonval_t json_createbool(bool val);
|
||
|
jsonval_t json_createnull(void);
|
||
|
void json_destroy(jsonval_t *val);
|
||
|
void json_write(FILE *out, jsonval_t *val);
|
||
|
|
||
|
#endif
|