libgson

gson.h
Login

File gson.h from the latest check-in


#ifndef _GSON_H
#define _GSON_H

struct gson;

// create json null
struct gson *gson_null(void);

// create json booleans
struct gson *gson_true(void);
struct gson *gson_false(void);

// create json number
struct gson *gson_nbr(double);

// create json string
struct gson *gson_str(const char *);


// json array:

// create json array
struct gson *gson_arr(void);

// add a single child to a json array
// if first argument is NULL, an array is created beforehand
struct gson *gson_arr_add(struct gson *arr, struct gson *child);

// add multiple childs to a json array:
// if first argument is NULL, an array is created beforehand.
// variadic arguments must be a succession of (struct gson *),
// NULL terminated.
struct gson *gson_arr_addv(struct gson *arr, ...);

// size of the json array
size_t gson_arr_size(struct gson *obj);


// json object:

// create json object
struct gson *gson_obj(void);

// add a single (key, value) to a json object
// if first argument is NULL, an object is created beforehand
struct gson *gson_obj_add(struct gson *obj, const char *key, struct gson* value);

// add multiple (key, values) pairs to a json oject:
// if first argument is NULL, an object is created beforehand
// variadic arguments must be a succession of (const char *, struct gson *),
// NULL terminated.
struct gson *gson_obj_addv(struct gson *obj, ...);

// size of the json object (number of members)
size_t gson_obj_size(struct gson *obj);


// render json to a malloced string:

// render in condensed form
char *gson_render(struct gson *);

// render in pretty indented form
char *gson_render_pretty(struct gson *);


// print json to stdout:

// print in condensed form
void gson_print(struct gson *);

// print in pretty indented form
void gson_print_pretty(struct gson *);


// free gson structure
void gson_free(struct gson *);

#endif