|
cwist
Modern C web framework with libttak runtime
|
json_builder.h interface. More...

Go to the source code of this file.
Classes | |
| struct | cwist_json_builder |
| Simple JSON string builder utility. More... | |
Typedefs | |
| typedef struct cwist_json_builder | cwist_json_builder |
Functions | |
| cwist_json_builder * | cwist_json_builder_create (void) |
| Allocate a new JSON builder with an empty output buffer. | |
| void | cwist_json_builder_destroy (cwist_json_builder *b) |
| Release a builder and its owned string buffer. | |
| void | cwist_json_begin_object (cwist_json_builder *b) |
| Begin a JSON object in the current builder context. | |
| void | cwist_json_end_object (cwist_json_builder *b) |
| Close the current JSON object. | |
| void | cwist_json_begin_array (cwist_json_builder *b, const char *key) |
| Begin a JSON array, optionally as the value for an object key. | |
| void | cwist_json_end_array (cwist_json_builder *b) |
| Close the current JSON array. | |
| void | cwist_json_add_string (cwist_json_builder *b, const char *key, const char *value) |
| Append a JSON string value. | |
| void | cwist_json_add_int (cwist_json_builder *b, const char *key, int value) |
| Append a JSON integer value. | |
| void | cwist_json_add_bool (cwist_json_builder *b, const char *key, bool value) |
| Append a JSON boolean literal. | |
| void | cwist_json_add_null (cwist_json_builder *b, const char *key) |
| Append a JSON null literal. | |
| const char * | cwist_json_get_raw (cwist_json_builder *b) |
| Returns the raw string buffer. Invalidated on destroy. | |
json_builder.h interface.
Definition in file json_builder.h.
| void cwist_json_add_bool | ( | cwist_json_builder * | b, |
| const char * | key, | ||
| bool | value | ||
| ) |
Append a JSON boolean literal.
Add a boolean value.
| b | Builder to update. NULL is ignored. |
| key | Object member name, or NULL when appending an array element. |
| value | Boolean payload to serialise as true or false. |
Definition at line 226 of file json_builder.c.
| void cwist_json_add_int | ( | cwist_json_builder * | b, |
| const char * | key, | ||
| int | value | ||
| ) |
Append a JSON integer value.
Add an integer value.
| b | Builder to update. NULL is ignored. |
| key | Object member name, or NULL when appending an array element. |
| value | Integer payload to format in base 10. |
Definition at line 210 of file json_builder.c.
| void cwist_json_add_null | ( | cwist_json_builder * | b, |
| const char * | key | ||
| ) |
Append a JSON null literal.
Add a null value.
| b | Builder to update. NULL is ignored. |
| key | Object member name, or NULL when appending an array element. |
Definition at line 239 of file json_builder.c.
Append a JSON string value.
Add a string value.
| b | Builder to update. NULL is ignored. |
| key | Object member name, or NULL when appending an array element. |
| value | String payload to emit verbatim between quotes. |
Definition at line 192 of file json_builder.c.
| void cwist_json_begin_array | ( | cwist_json_builder * | b, |
| const char * | key | ||
| ) |
Begin a JSON array, optionally as the value for an object key.
Begin a JSON array.
| b | Builder to update. NULL is ignored. |
| key | Object member name, or NULL when emitting a bare array value. |
Definition at line 164 of file json_builder.c.
| void cwist_json_begin_object | ( | cwist_json_builder * | b | ) |
Begin a JSON object in the current builder context.
Begin a JSON object.
| b | Builder to update. NULL is ignored. |
Definition at line 142 of file json_builder.c.
| cwist_json_builder * cwist_json_builder_create | ( | void | ) |
Allocate a new JSON builder with an empty output buffer.
Create a new JSON builder.
The builder keeps only a minimal amount of state: the backing string buffer and whether the next value must be prefixed with a comma.
Definition at line 21 of file json_builder.c.
| void cwist_json_builder_destroy | ( | cwist_json_builder * | b | ) |
Release a builder and its owned string buffer.
Destroy a JSON builder.
| b | Builder instance to destroy. NULL is ignored. |
Definition at line 37 of file json_builder.c.
| void cwist_json_end_array | ( | cwist_json_builder * | b | ) |
Close the current JSON array.
End a JSON array.
| b | Builder to update. NULL is ignored. |
Definition at line 180 of file json_builder.c.
| void cwist_json_end_object | ( | cwist_json_builder * | b | ) |
Close the current JSON object.
End a JSON object.
| b | Builder to update. NULL is ignored. |
Definition at line 153 of file json_builder.c.
| const char * cwist_json_get_raw | ( | cwist_json_builder * | b | ) |
Returns the raw string buffer. Invalidated on destroy.
Returns the raw string buffer. Invalidated on destroy.
| b | Builder whose buffer should be observed. |
Definition at line 252 of file json_builder.c.