Skip to content

json.cjson #

fn create_array #

fn create_array() &Node

create_array creates a new JSON array item. Use .add_item_to_array(value) calls, to add items to it later.

fn create_bool #

fn create_bool(val bool) &Node

create_bool creates a new JSON boolean item.

fn create_false #

fn create_false() &Node

create_false creates a new JSON boolean item, with value false.

fn create_null #

fn create_null() &Node

create_null creates a new JSON NULL item, with the value null. It symbolises a missing value for a given key in an object.

fn create_number #

fn create_number(val f64) &Node

create_number creates a new JSON number item.

fn create_object #

fn create_object() &Node

create_object creates a new JSON object/map item. Use .add_item_to_object(key, value) calls, to add other items to it later.

fn create_raw #

fn create_raw(const_val string) &Node

create_raw creates a new JSON RAW string item.

fn create_string #

fn create_string(val string) &Node

create_string creates a new JSON string item.

fn create_true #

fn create_true() &Node

create_true creates a new JSON boolean item, with value true.

fn delete #

unsafe
fn delete(node &Node)

delete removes the given node from memory. NB: DO NOT USE that node, after you have called unsafe { delete(node) } !

fn version #

fn version() string

version returns the version of cJSON as a string

type Node #

type Node = C.cJSON

fn (Node) add_item_to_object #

fn (mut obj Node) add_item_to_object(key string, item &Node)

add_item_to_array adds the given item to the object, under the given key.

fn (Node) add_item_to_array #

fn (mut obj Node) add_item_to_array(item &Node)

add_item_to_array append the given item to the object.

fn (Node) print #

fn (mut obj Node) print() string

print serialises the node to a string, formatting its structure, so the resulting string is more prettier/human readable.

fn (Node) print_unformatted #

fn (mut obj Node) print_unformatted() string

print serialises the node to a string, without formatting its structure, so the resulting string is shorter/cheaper to transmit.

fn (Node) str #

fn (mut obj Node) str() string

str returns the unformatted serialisation to string of the given Node.

struct C.cJSON #

@[typedef]
struct C.cJSON {
pub:
	next  &C.cJSON // next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem
	prev  &C.cJSON
	child &C.cJSON // An array or object item will have a child pointer pointing to a chain of the items in the array/object

	type int // The type of the item, as above

	valueint    int   // writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead
	valuedouble f64   // The item's number, if type==cJSON_Number
	valuestring &char // The item's string, if type==cJSON_String  and type == cJSON_Raw
	// @string &char // The item's name string, if this item is the child of, or is in the list of subitems of an object
	// TODO: `@string &char` from above does not work. It should be fixed, at least inside `struct C.`.
}