-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibjson.h
More file actions
60 lines (48 loc) · 1.59 KB
/
libjson.h
File metadata and controls
60 lines (48 loc) · 1.59 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* SPDX-License-Identifier: LGPL-3.0-or-later */
#ifndef _LIBJSON_H_
#define _LIBJSON_H_
#include <stdbool.h>
#include "hashtable.h"
typedef enum entry_type {
UNKNOWN,
NIL,
BOOL,
STRING,
NUMBER,
ARRAY,
OBJECT
} entry_type;
typedef struct json_entry {
void *item;
entry_type type;
} json_entry_t;
typedef hashtable_t json_obj_t;
typedef struct json_array {
json_entry_t *entries;
size_t size;
size_t capacity;
} json_array_t;
// string must be null terminated, also the returned value is heap allocated
json_entry_t *json_parse(const char *);
// returned value is heap allocated
char *json_stringify(const json_entry_t *, size_t *);
void json_destroy(json_entry_t *);
json_obj_t *json_get_obj(const json_entry_t *);
json_array_t *json_get_array(const json_entry_t *);
// key must be null terminated
json_entry_t *json_get_obj_entry(const json_obj_t *, const char *);
bool json_get_bool(const json_entry_t *);
char *json_get_string(const json_entry_t *);
long double json_get_number(const json_entry_t *);
json_entry_t *json_create_obj();
json_entry_t *json_create_array();
json_entry_t *json_create_string(const char *, size_t);
json_entry_t *json_create_number(long double);
json_entry_t *json_create_bool(bool);
json_entry_t *json_create_null();
void json_insert_obj_entry(json_obj_t *, const char *, size_t, json_entry_t *);
void json_remove_obj_entry(json_obj_t *, const char *);
void json_insert_array_entry(json_array_t *, const json_entry_t *);
void json_remove_array_entry(json_array_t *, size_t);
void json_nullify_entry(json_entry_t *);
#endif // _LIBJSON_H_