File syn_json_write.h¶
FileList > src > syntropic > util > syn_json_write.h
Go to the source code of this file
Streaming JSON builder — zero-alloc, caller-provided buffer. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_JsonWriter Streaming JSON writer — tracks nesting, commas, and overflow. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_json_arr_close (SYN_JsonWriter * w) Close a JSON array ] . |
| void | syn_json_arr_open (SYN_JsonWriter * w) Open a JSON array [ . |
| void | syn_json_init (SYN_JsonWriter * w, char * buf, size_t capacity) Initialize a JSON writer. |
| void | syn_json_key (SYN_JsonWriter * w, const char * key) Write a bare key "key": for nested objects/arrays. |
| void | syn_json_key_bool (SYN_JsonWriter * w, const char * key, bool val) Write "key":true or"key":false . |
| void | syn_json_key_int (SYN_JsonWriter * w, const char * key, int32_t val) Write "key":123 . |
| void | syn_json_key_null (SYN_JsonWriter * w, const char * key) Write "key":null . |
| void | syn_json_key_str (SYN_JsonWriter * w, const char * key, const char * val) Write "key":"value" . Escapes" and\\ in value. |
| void | syn_json_key_uint (SYN_JsonWriter * w, const char * key, uint32_t val) Write "key":123 (unsigned). |
| void | syn_json_obj_close (SYN_JsonWriter * w) Close a JSON object } . |
| void | syn_json_obj_open (SYN_JsonWriter * w) Open a JSON object { . |
| void | syn_json_val_bool (SYN_JsonWriter * w, bool val) Append a boolean value to an array. |
| void | syn_json_val_int (SYN_JsonWriter * w, int32_t val) Append an integer value to an array. |
| void | syn_json_val_str (SYN_JsonWriter * w, const char * val) Append a string value to an array. |
| void | syn_json_val_uint (SYN_JsonWriter * w, uint32_t val) Append an unsigned integer value to an array. |
Public Static Functions¶
| Type | Name |
|---|---|
| size_t | syn_json_len (const SYN_JsonWriter * w) Get the number of bytes written. |
| bool | syn_json_ok (const SYN_JsonWriter * w) Check if the writer is in a valid state (no overflow). |
| const char * | syn_json_str (const SYN_JsonWriter * w) Get the null-terminated output string. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_JSON_MAX_DEPTH 8 |
Detailed Description¶
Builds JSON output incrementally into a fixed buffer. Handles auto-commas, nesting, and overflow detection. No parser — this is write-only for building API responses, telemetry payloads, etc.
** **
char buf[256];
SYN_JsonWriter w;
syn_json_init(&w, buf, sizeof(buf));
syn_json_obj_open(&w);
syn_json_key_str(&w, "device", "esp32");
syn_json_key_int(&w, "uptime", 12345);
syn_json_key_bool(&w, "wifi", true);
syn_json_obj_close(&w);
// buf = {"device":"esp32","uptime":12345,"wifi":true}
Public Functions Documentation¶
function syn_json_arr_close¶
Close a JSON array ] .
Parameters:
wWriter.
function syn_json_arr_open¶
Open a JSON array [ .
Parameters:
wWriter.
function syn_json_init¶
Initialize a JSON writer.
Parameters:
wWriter instance.bufOutput buffer.capacityBuffer size in bytes.
function syn_json_key¶
Write a bare key "key": for nested objects/arrays.
Follow with syn_json_obj_open() or syn_json_arr_open().
Parameters:
wWriter.keyJSON key.
function syn_json_key_bool¶
Write "key":true or"key":false .
Parameters:
wWriter.keyJSON key.valBoolean value.
function syn_json_key_int¶
Write "key":123 .
Parameters:
wWriter.keyJSON key.valInteger value.
function syn_json_key_null¶
Write "key":null .
Parameters:
wWriter.keyJSON key.
function syn_json_key_str¶
Write "key":"value" . Escapes" and\\ in value.
Parameters:
wWriter.keyJSON key.valString value.
function syn_json_key_uint¶
Write "key":123 (unsigned).
Parameters:
wWriter.keyJSON key.valUnsigned integer value.
function syn_json_obj_close¶
Close a JSON object } .
Parameters:
wWriter.
function syn_json_obj_open¶
Open a JSON object { .
Parameters:
wWriter.
function syn_json_val_bool¶
Append a boolean value to an array.
Parameters:
wWriter.valBoolean value.
function syn_json_val_int¶
Append an integer value to an array.
Parameters:
wWriter.valInteger value.
function syn_json_val_str¶
Append a string value to an array.
Parameters:
wWriter.valString value.
function syn_json_val_uint¶
Append an unsigned integer value to an array.
Parameters:
wWriter.valUnsigned value.
Public Static Functions Documentation¶
function syn_json_len¶
Get the number of bytes written.
Parameters:
wWriter.
Returns:
Byte count.
function syn_json_ok¶
Check if the writer is in a valid state (no overflow).
Parameters:
wWriter.
Returns:
true if no overflow occurred.
function syn_json_str¶
Get the null-terminated output string.
Parameters:
wWriter.
Returns:
Pointer to the output buffer.
Macro Definition Documentation¶
define SYN_JSON_MAX_DEPTH¶
Maximum nesting depth
The documentation for this class was generated from the following file src/syntropic/util/syn_json_write.h