Skip to content

File syn_json_write.c

FileList > src > syntropic > util > syn_json_write.c

Go to the source code of this file

Streaming JSON builder implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_json_write.h"
  • #include <string.h>

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
void jw_comma (SYN_JsonWriter * w)
Insert comma separator if needed.
void jw_int (SYN_JsonWriter * w, int32_t val)
Write a signed integer.
void jw_putc (SYN_JsonWriter * w, char ch)
Append a single char to the output buffer.
void jw_puts (SYN_JsonWriter * w, const char * s)
Append a raw string (no escaping).
void jw_str (SYN_JsonWriter * w, const char * s)
Write an escaped JSON string (with surrounding quotes).
void jw_uint (SYN_JsonWriter * w, uint32_t val)
Write an unsigned integer.

Public Functions Documentation

function syn_json_arr_close

Close a JSON array ] .

void syn_json_arr_close (
    SYN_JsonWriter * w
) 

Parameters:

  • w Writer.

function syn_json_arr_open

Open a JSON array [ .

void syn_json_arr_open (
    SYN_JsonWriter * w
) 

Parameters:

  • w Writer.

function syn_json_init

Initialize a JSON writer.

void syn_json_init (
    SYN_JsonWriter * w,
    char * buf,
    size_t capacity
) 

Parameters:

  • w Writer instance.
  • buf Output buffer.
  • capacity Buffer size in bytes.

function syn_json_key

Write a bare key "key": for nested objects/arrays.

void syn_json_key (
    SYN_JsonWriter * w,
    const char * key
) 

Follow with syn_json_obj_open() or syn_json_arr_open().

Parameters:

  • w Writer.
  • key JSON key.

function syn_json_key_bool

Write "key":true or"key":false .

void syn_json_key_bool (
    SYN_JsonWriter * w,
    const char * key,
    bool val
) 

Parameters:

  • w Writer.
  • key JSON key.
  • val Boolean value.

function syn_json_key_int

Write "key":123 .

void syn_json_key_int (
    SYN_JsonWriter * w,
    const char * key,
    int32_t val
) 

Parameters:

  • w Writer.
  • key JSON key.
  • val Integer value.

function syn_json_key_null

Write "key":null .

void syn_json_key_null (
    SYN_JsonWriter * w,
    const char * key
) 

Parameters:

  • w Writer.
  • key JSON key.

function syn_json_key_str

Write "key":"value" . Escapes" and\\ in value.

void syn_json_key_str (
    SYN_JsonWriter * w,
    const char * key,
    const char * val
) 

Parameters:

  • w Writer.
  • key JSON key.
  • val String value.

function syn_json_key_uint

Write "key":123 (unsigned).

void syn_json_key_uint (
    SYN_JsonWriter * w,
    const char * key,
    uint32_t val
) 

Parameters:

  • w Writer.
  • key JSON key.
  • val Unsigned integer value.

function syn_json_obj_close

Close a JSON object } .

void syn_json_obj_close (
    SYN_JsonWriter * w
) 

Parameters:

  • w Writer.

function syn_json_obj_open

Open a JSON object { .

void syn_json_obj_open (
    SYN_JsonWriter * w
) 

Parameters:

  • w Writer.

function syn_json_val_bool

Append a boolean value to an array.

void syn_json_val_bool (
    SYN_JsonWriter * w,
    bool val
) 

Parameters:

  • w Writer.
  • val Boolean value.

function syn_json_val_int

Append an integer value to an array.

void syn_json_val_int (
    SYN_JsonWriter * w,
    int32_t val
) 

Parameters:

  • w Writer.
  • val Integer value.

function syn_json_val_str

Append a string value to an array.

void syn_json_val_str (
    SYN_JsonWriter * w,
    const char * val
) 

Parameters:

  • w Writer.
  • val String value.

function syn_json_val_uint

Append an unsigned integer value to an array.

void syn_json_val_uint (
    SYN_JsonWriter * w,
    uint32_t val
) 

Parameters:

  • w Writer.
  • val Unsigned value.

Public Static Functions Documentation

function jw_comma

Insert comma separator if needed.

static void jw_comma (
    SYN_JsonWriter * w
) 

Parameters:

  • w JSON writer.

function jw_int

Write a signed integer.

static void jw_int (
    SYN_JsonWriter * w,
    int32_t val
) 

Parameters:

  • w JSON writer.
  • val Value to write.

function jw_putc

Append a single char to the output buffer.

static void jw_putc (
    SYN_JsonWriter * w,
    char ch
) 

Parameters:

  • w JSON writer.
  • ch Character to append.

function jw_puts

Append a raw string (no escaping).

static void jw_puts (
    SYN_JsonWriter * w,
    const char * s
) 

Parameters:

  • w JSON writer.
  • s String to append.

function jw_str

Write an escaped JSON string (with surrounding quotes).

static void jw_str (
    SYN_JsonWriter * w,
    const char * s
) 

Parameters:

  • w JSON writer.
  • s String to encode.

function jw_uint

Write an unsigned integer.

static void jw_uint (
    SYN_JsonWriter * w,
    uint32_t val
) 

Parameters:

  • w JSON writer.
  • val Value to write.


The documentation for this class was generated from the following file src/syntropic/util/syn_json_write.c