53 lines
1.4 KiB
C
53 lines
1.4 KiB
C
#ifndef MONS_JSON_H
|
|
#define MONS_JSON_H
|
|
|
|
#include <stdbool.h>
|
|
#include "hashmap.h"
|
|
|
|
struct mons_json_value;
|
|
union mons_json_entry;
|
|
|
|
typedef struct mons_json_array {
|
|
struct mons_json_value *values;
|
|
unsigned int len;
|
|
} mons_json_array;
|
|
|
|
typedef union mons_json_value_data {
|
|
char *string;
|
|
float number;
|
|
mons_hashmap object;
|
|
mons_json_array array;
|
|
bool boolean;
|
|
void *null;
|
|
} mons_json_value_data;
|
|
|
|
typedef enum mons_json_value_type {
|
|
MONS_JSON_STRING,
|
|
MONS_JSON_NUMBER,
|
|
MONS_JSON_OBJECT,
|
|
MONS_JSON_ARRAY,
|
|
MONS_JSON_BOOL,
|
|
MONS_JSON_NULL,
|
|
} mons_json_value_type;
|
|
|
|
typedef struct mons_json_value {
|
|
mons_json_value_type type;
|
|
mons_json_value_data data;
|
|
} mons_json_value;
|
|
|
|
int mons_json_parse(char *json, mons_json_value *out);
|
|
|
|
char *mons_json_to_string(mons_json_value json);
|
|
|
|
void mons_json_free(mons_json_value json);
|
|
|
|
int mons_json_get_value(mons_json_value json, char *name, mons_json_value *out);
|
|
int mons_json_get_int(mons_json_value json, char *name, int *out);
|
|
int mons_json_get_float(mons_json_value json, char *name, float *out);
|
|
int mons_json_get_bool(mons_json_value json, char *name, bool *out);
|
|
int mons_json_get_array(mons_json_value json, char *name, mons_json_array *out);
|
|
int mons_json_get_object(mons_json_value json, char *name, mons_hashmap *out);
|
|
int mons_json_get_string(mons_json_value json, char *name, char **out);
|
|
|
|
#endif
|