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

Go to the source code of this file.

Classes

struct  SJPair
 an object is a list of key/value pairs More...
 

Functions

int sj_object_check (SJson *json)
 
void sj_pair_free (SJPair *pair)
 
SJPairsj_pair_new (char *key, SJson *value)
 
void sj_object_insert (SJson *object, char *key, SJson *value)
 insert data into a json object More...
 
SJsonsj_object_copy (SJson *json)
 
SJsonsj_object_new ()
 allocate a new empty json object More...
 
void sj_object_free (SJson *object)
 free a previously allocated json object More...
 
SJsonsj_object_get_value (SJson *object, char *key)
 get the json value from an object given a key More...
 
char * sj_object_get_value_as_string (SJson *object, char *key)
 
SJStringsj_object_to_json_string (SJson *object)
 get the json object back as a formatted json string More...
 

Function Documentation

int sj_object_check ( SJson json)

Definition at line 10 of file simple_json_object.c.

SJson* sj_object_copy ( SJson json)

Definition at line 69 of file simple_json_object.c.

void sj_object_free ( SJson object)

free a previously allocated json object

Parameters
objectthe object to free

Definition at line 100 of file simple_json_object.c.

SJson* sj_object_get_value ( SJson object,
char *  key 
)

get the json value from an object given a key

Parameters
objectthe hson object to get
keythe key to search by
Returns
NULL on error, or if no object provided or it is not of object or the key is not found, the value otherwise
Note
: the json returned is OWNED by the parent object do not free it.

Definition at line 116 of file simple_json_object.c.

char* sj_object_get_value_as_string ( SJson object,
char *  key 
)

Definition at line 134 of file simple_json_object.c.

void sj_object_insert ( SJson object,
char *  key,
SJson value 
)

insert data into a json object

Parameters
objectthe json object to insert into
keythe string to identify the object value with
valuethe value of the key
Note
: this is a no-op if object is not an actual JSON object

Definition at line 58 of file simple_json_object.c.

SJson* sj_object_new ( )

allocate a new empty json object

Returns
NULL on memory allocation error, an empty SJson object otherwise

Definition at line 87 of file simple_json_object.c.

SJString* sj_object_to_json_string ( SJson object)

get the json object back as a formatted json string

Parameters
objectthe object to convert
Returns
NULL on error, or a string encapsulated ith {}

Definition at line 143 of file simple_json_object.c.

void sj_pair_free ( SJPair pair)

Definition at line 30 of file simple_json_object.c.

SJPair* sj_pair_new ( char *  key,
SJson value 
)

Definition at line 38 of file simple_json_object.c.