Simple JSON  0.1
A free simple json library for C
simple_json.h
Go to the documentation of this file.
1 #ifndef __SIMPLE_JSON_H__
2 #define __SIMPLE_JSON_H__
3 
4 #include "simple_json_list.h"
5 #include "simple_json_array.h"
6 #include "simple_json_string.h"
7 #include "simple_json_object.h"
8 #include "simple_json_error.h"
9 
13 void sj_free(SJson *sjs);
14 
21 SJson *sj_copy(SJson *json);
22 
28 SJson *sj_load(const char *filename);
29 
35 void sj_save(SJson *json,char *filename);
36 
42 SJson *sj_new_str(char *str);
43 
50 const char *sj_get_string_value(SJson *json);
51 
59 int sj_get_integer_value(SJson *json,int *i);
60 
68 int sj_get_float_value(SJson *json,float *f);
69 
77 int sj_get_bool_value(SJson *json,short int *b);
78 
84 SJson *sj_new_int(int i);
85 
91 SJson *sj_new_float(float f);
92 
98 SJson *sj_new_bool(int b);
99 
104 SJson *sj_null_new();
105 
111 
119 void sj_object_insert(SJson *object,char *key,SJson *value);
120 
128 SJson *sj_object_get_value(SJson *object,char *key);
129 
135 
142 void sj_array_append(SJson *array,SJson *value);
143 
149 int sj_array_get_count(SJson *array);
150 
157 SJson *sj_array_get_nth(SJson *array,int n);
158 
163 void sj_echo(SJson *json);
164 
170 int sj_is_array(SJson *json);
171 
177 int sj_is_object(SJson *json);
178 
184 int sj_is_string(SJson *json);
185 
191 int sj_is_number(SJson *json);
192 
198 int sj_is_bool(SJson *json);
199 
205 int sj_is_null(SJson *json);
206 
207 
208 #endif
int sj_is_object(SJson *json)
check if the json is an object
Definition: simple_json.c:215
SJson * sj_array_new()
allocate a new empty json array
SJson * sj_new_str(char *str)
make a new json value that is a string
Definition: simple_json.c:9
SJson * sj_load(const char *filename)
loads and parses a json file
Definition: simple_json.c:47
int sj_get_bool_value(SJson *json, short int *b)
get the json value as a bool Can be used to check for existence
Definition: simple_json.c:202
this is the abstract container structure for all json data This structure may be an object...
void sj_array_append(SJson *array, SJson *value)
append to a JSON array a new value
SJson * sj_array_get_nth(SJson *array, int n)
retrieve the nth element in the json array
SJson * sj_new_float(float f)
make a new json value that is a float
Definition: simple_json.c:19
void sj_echo(SJson *json)
print the contents of the json file to stdout
Definition: simple_json.c:140
const char * sj_get_string_value(SJson *json)
get the JSON value as a string
Definition: simple_json.c:184
void sj_free(SJson *sjs)
frees a previously loaded json struct
Definition: simple_json.c:116
int sj_array_get_count(SJson *array)
get the number of elements in the json array
int sj_is_array(SJson *json)
check if the json is an array
Definition: simple_json.c:208
int sj_get_float_value(SJson *json, float *f)
get the json value as a float Can be used to check for existence
Definition: simple_json.c:196
SJson * sj_object_get_value(SJson *object, char *key)
get the json value from an object given a key
int sj_is_string(SJson *json)
check if the json is a string
Definition: simple_json.c:222
int sj_is_null(SJson *json)
check if the json is NULL
Definition: simple_json.c:243
void sj_object_insert(SJson *object, char *key, SJson *value)
insert data into a json object
SJson * sj_null_new()
make a new json value that is NULL
Definition: simple_json.c:173
SJson * sj_object_new()
allocate a new empty json object
int sj_is_bool(SJson *json)
check if the json is a bool
Definition: simple_json.c:236
int sj_is_number(SJson *json)
check if the json is a number
Definition: simple_json.c:229
SJson * sj_new_bool(int b)
make a new json value that is a bool
Definition: simple_json.c:24
SJson * sj_new_int(int i)
make a new json value that is an integer
Definition: simple_json.c:14
void sj_save(SJson *json, char *filename)
write a json value as a formatted json string to file
Definition: simple_json.c:123
SJson * sj_copy(SJson *json)
make a duplicate of a json structure.
Definition: simple_json.c:109
int sj_get_integer_value(SJson *json, int *i)
get the json value as an integer Can be used to check for existence
Definition: simple_json.c:190