Simple JSON  0.1
A free simple json library for C
simple_json.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "simple_json.h"
#include "simple_json_string.h"
#include "simple_json_parse.h"
#include "simple_json_error.h"
Include dependency graph for simple_json.c:

Go to the source code of this file.

Functions

SJsonsj_new_str (char *str)
 make a new json value that is a string More...
 
SJsonsj_new_int (int i)
 make a new json value that is an integer More...
 
SJsonsj_new_float (float f)
 make a new json value that is a float More...
 
SJsonsj_new_bool (int b)
 make a new json value that is a bool More...
 
long get_file_Size (FILE *file)
 
SJsonsj_load (const char *filename)
 loads and parses a json file More...
 
SJsonsj_new ()
 allocate a new empty json object More...
 
SJsonsj_copy (SJson *json)
 make a duplicate of a json structure. More...
 
void sj_free (SJson *json)
 frees a previously loaded json struct More...
 
void sj_save (SJson *json, char *filename)
 write a json value as a formatted json string to file More...
 
void sj_echo (SJson *json)
 print the contents of the json file to stdout More...
 
void sj_null_free (SJson *json)
 
SJStringsj_value_to_json_string (SJson *json)
 convert the json value into a json string More...
 
SJStringsj_null_to_json_string (SJson *json)
 
SJsonsj_null_copy (SJson *json)
 
SJsonsj_null_new ()
 make a new json value that is NULL More...
 
const char * sj_get_string_value (SJson *json)
 get the JSON value as a string More...
 
int sj_get_integer_value (SJson *json, int *i)
 get the json value as an integer Can be used to check for existence More...
 
int sj_get_float_value (SJson *json, float *f)
 get the json value as a float Can be used to check for existence More...
 
int sj_get_bool_value (SJson *json, short int *b)
 get the json value as a bool Can be used to check for existence More...
 
int sj_is_array (SJson *json)
 check if the json is an array More...
 
int sj_is_object (SJson *json)
 check if the json is an object More...
 
int sj_is_string (SJson *json)
 check if the json is a string More...
 
int sj_is_number (SJson *json)
 check if the json is a number More...
 
int sj_is_bool (SJson *json)
 check if the json is a bool More...
 
int sj_is_null (SJson *json)
 check if the json is NULL More...
 

Function Documentation

long get_file_Size ( FILE *  file)

Definition at line 29 of file simple_json.c.

SJson* sj_copy ( SJson json)

make a duplicate of a json structure.

Note
the duplicate needs to be sj_free()'d separately
Parameters
jsonthe json to be duplicated
Returns
NULL on error, or a Duplicate json

Definition at line 109 of file simple_json.c.

void sj_echo ( SJson json)

print the contents of the json file to stdout

Parameters
jsonthe json struct to print

Definition at line 140 of file simple_json.c.

void sj_free ( SJson json)

frees a previously loaded json struct

Definition at line 116 of file simple_json.c.

int sj_get_bool_value ( SJson json,
short int *  b 
)

get the json value as a bool Can be used to check for existence

Parameters
jsonthe json value to get from
b[optional] place to write the output to
Returns
0 if the json did not contain a bool or if there was an error, 1 otherwise

Definition at line 202 of file simple_json.c.

int sj_get_float_value ( SJson json,
float *  f 
)

get the json value as a float Can be used to check for existence

Parameters
jsonthe json value to get from
f[optional] place to write the output to
Returns
0 if the json did not contain a float or if there was an error, 1 otherwise

Definition at line 196 of file simple_json.c.

int sj_get_integer_value ( SJson json,
int *  i 
)

get the json value as an integer Can be used to check for existence

Parameters
jsonthe json value to get from
i[optional] place to write the output to
Returns
0 if the json did not contain an integer or if there was an error, 1 otherwise

Definition at line 190 of file simple_json.c.

const char* sj_get_string_value ( SJson json)

get the JSON value as a string

Parameters
jsonthe json value to get the string from
Returns
NULL if the provided json was not a string or on error, the string otherwise
Note
: the returned value should not be altered or freed

Definition at line 184 of file simple_json.c.

int sj_is_array ( SJson json)

check if the json is an array

Parameters
jsonthe json to check
Returns
1 if it is, 0 if not

Definition at line 208 of file simple_json.c.

int sj_is_bool ( SJson json)

check if the json is a bool

Parameters
jsonthe json to check
Returns
1 if it is, 0 if not

Definition at line 236 of file simple_json.c.

int sj_is_null ( SJson json)

check if the json is NULL

Parameters
jsonthe json to check
Returns
1 if it is, 0 if not

Definition at line 243 of file simple_json.c.

int sj_is_number ( SJson json)

check if the json is a number

Parameters
jsonthe json to check
Returns
1 if it is, 0 if not

Definition at line 229 of file simple_json.c.

int sj_is_object ( SJson json)

check if the json is an object

Parameters
jsonthe json to check
Returns
1 if it is, 0 if not

Definition at line 215 of file simple_json.c.

int sj_is_string ( SJson json)

check if the json is a string

Parameters
jsonthe json to check
Returns
1 if it is, 0 if not

Definition at line 222 of file simple_json.c.

SJson* sj_load ( const char *  filename)

loads and parses a json file

Parameters
filenamethe file to parse
Returns
NULL on error or an SJS pointer

Definition at line 47 of file simple_json.c.

SJson* sj_new ( )

allocate a new empty json object

Returns
NULL on error or a new json object

Definition at line 96 of file simple_json.c.

SJson* sj_new_bool ( int  b)

make a new json value that is a bool

Parameters
bthe boolean value (1 is true, 0 is false)
Returns
NULL on error or a new json that holds a bool value

Definition at line 24 of file simple_json.c.

SJson* sj_new_float ( float  f)

make a new json value that is a float

Parameters
fthe float value
Returns
NULL on error or a new json that holds a floating point value

Definition at line 19 of file simple_json.c.

SJson* sj_new_int ( int  i)

make a new json value that is an integer

Parameters
ithe integer value
Returns
NULL on error or a new json that holds an integer value

Definition at line 14 of file simple_json.c.

SJson* sj_new_str ( char *  str)

make a new json value that is a string

Parameters
strthe string to base the json value on
Returns
NULL on error or a new json that holds a string value

Definition at line 9 of file simple_json.c.

SJson* sj_null_copy ( SJson json)

Definition at line 168 of file simple_json.c.

void sj_null_free ( SJson json)

Definition at line 150 of file simple_json.c.

SJson* sj_null_new ( )

make a new json value that is NULL

Returns
NULL on error (Ironically) or a new json that holds a NULL value

Definition at line 173 of file simple_json.c.

SJString* sj_null_to_json_string ( SJson json)

Definition at line 163 of file simple_json.c.

void sj_save ( SJson json,
char *  filename 
)

write a json value as a formatted json string to file

Parameters
jsonthe struct to convert and write
filenamethe file to overwrite

Definition at line 123 of file simple_json.c.

SJString* sj_value_to_json_string ( SJson json)

convert the json value into a json string

Parameters
jsonthe value to convert
Returns
NULL on error or the json string

Definition at line 156 of file simple_json.c.