c0
C0DATA — structured data using ASCII C0 control codes (C)
Loading...
Searching...
No Matches
c0_json.h File Reference
#include "c0.h"

Go to the source code of this file.

Data Structures

struct  c0_json_pair
struct  c0_json_value

Typedefs

typedef struct c0_json_value c0_json_value

Enumerations

enum  c0_json_kind { C0_JSON_STR , C0_JSON_ARRAY , C0_JSON_OBJECT }

Functions

c0_json_value * c0_json_str (const char *s, size_t len)
c0_json_value * c0_json_array (void)
c0_json_value * c0_json_object (void)
int c0_json_array_push (c0_json_value *arr, c0_json_value *item)
 takes ownership of item
int c0_json_object_push (c0_json_value *obj, const char *key, size_t key_len, c0_json_value *val)
 copies key, owns val
void c0_json_free (c0_json_value *v)
c0_json_value * c0_to_value (const uint8_t *buf, size_t len, c0_error *err)
 A value tree from C0DATA bytes (the first document's body).
uint8_t * c0_from_value (const c0_json_value *v, const char *group_name, size_t *out_len)
 A value tree as C0DATA compact bytes (malloc'd; caller frees).
c0_json_value * c0_json_parse (const char *json, size_t len)
 Parse JSON text into a value tree (numbers/bools become strings, null the empty string).
char * c0_json_print (const c0_json_value *v, size_t *out_len)
 Serialize a value tree to pretty JSON (2-space indent), NUL-terminated and malloc'd (caller frees).
char * c0_to_json (const uint8_t *buf, size_t len, size_t *out_len, c0_error *err)
 C0DATA bytes → pretty JSON string (malloc'd, NUL-terminated).
uint8_t * c0_from_json (const char *json, size_t len, const char *group_name, size_t *out_len)
 JSON text → C0DATA compact bytes (malloc'd).

Typedef Documentation

◆ c0_json_value

typedef struct c0_json_value c0_json_value

Enumeration Type Documentation

◆ c0_json_kind

Enumerator
C0_JSON_STR 
C0_JSON_ARRAY 
C0_JSON_OBJECT 

Function Documentation

◆ c0_from_json()

uint8_t * c0_from_json ( const char * json,
size_t len,
const char * group_name,
size_t * out_len )

JSON text → C0DATA compact bytes (malloc'd).

group_name as for c0_from_value. NULL on parse error or allocation failure.

◆ c0_from_value()

uint8_t * c0_from_value ( const c0_json_value * v,
const char * group_name,
size_t * out_len )

A value tree as C0DATA compact bytes (malloc'd; caller frees).

group_name names the group for data that has none ("data" when NULL). NULL on allocation failure.

◆ c0_json_array()

c0_json_value * c0_json_array ( void )

◆ c0_json_array_push()

int c0_json_array_push ( c0_json_value * arr,
c0_json_value * item )

takes ownership of item

◆ c0_json_free()

void c0_json_free ( c0_json_value * v)

◆ c0_json_object()

c0_json_value * c0_json_object ( void )

◆ c0_json_object_push()

int c0_json_object_push ( c0_json_value * obj,
const char * key,
size_t key_len,
c0_json_value * val )

copies key, owns val

◆ c0_json_parse()

c0_json_value * c0_json_parse ( const char * json,
size_t len )

Parse JSON text into a value tree (numbers/bools become strings, null the empty string).

NULL on parse error or allocation failure.

◆ c0_json_print()

char * c0_json_print ( const c0_json_value * v,
size_t * out_len )

Serialize a value tree to pretty JSON (2-space indent), NUL-terminated and malloc'd (caller frees).

NULL on allocation failure.

◆ c0_json_str()

c0_json_value * c0_json_str ( const char * s,
size_t len )

◆ c0_to_json()

char * c0_to_json ( const uint8_t * buf,
size_t len,
size_t * out_len,
c0_error * err )

C0DATA bytes → pretty JSON string (malloc'd, NUL-terminated).

◆ c0_to_value()

c0_json_value * c0_to_value ( const uint8_t * buf,
size_t len,
c0_error * err )

A value tree from C0DATA bytes (the first document's body).

NULL on malformed input (detail in *err when given) or allocation failure.