Function reference

Object

Append

The json_object_append_* append value at the end of the object.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

Note

If the key already exists in the object the function fails and json_errno is set to JSON_E_KEY_ALREADY_EXIST.

group EditorAppendObject

Functions

int json_object_append_bool(json_object_t *obj, char const *key, bool value)
int json_object_append_nb(json_object_t *obj, char const *key, int value)
int json_object_append_str_dup(json_object_t *obj, char const *key, char const *value)

The added value is a copy of value.

int json_object_append_str(json_object_t *obj, char const *key, char *value)

The function takes ownership of the value’s pointer.

int json_object_append_null(json_object_t *obj, char const *key)
int json_object_append_object(json_object_t *obj, char const *key, json_object_t *value)

The function takes ownership of the value’s pointer.

int json_object_append_array(json_object_t *obj, char const *key, json_array_t *value)

The function takes ownership of the value’s pointer.

Compare

group EditorCompareObject

Functions

bool json_object_compare(json_object_t const *obj1, json_object_t const *obj2)

The function compares obj1 with obj2. Equality is defined as follows:

  • json_object_elements of different type are never equal

  • json_object_elements of the same primitive type are equal if the c-representation of their value is equal

  • see json_array_compare for the equality criteria of the array

  • keys must be in the same order in the two objects

Return

true if the objects are equal, false otherewise.

Create

group EditorCreateObject

Functions

json_object_t *json_object_create(void)

The function creates an empty json_object_t.

Return

On success the function returns a pointer to a new json_object_t. On failure NULL is returned and json_errno is set to JSON_E_SYS_FAILURE.

Destroy

group EditorDestroyObject

Functions

void json_object_destroy(json_object_t *obj)

The function releases the allocated resources for obj.

Extract

The json_object_extract_*_by_index extract the value from the object and sets *value with it. The object’s element is then set to JSON_NULL type. If the index is out of bound or the value’s type at index doesn’t match, the function fails and both value and object are left untouched.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group EditorExtractIndexObject

Functions

int json_object_extract_bool_by_index(json_object_t *object, size_t index, bool *value)
int json_object_extract_nb_by_index(json_object_t *object, size_t index, int *value)
int json_object_extract_string_by_index(json_object_t *object, size_t index, char **value)

Note

The ownership of the returned value is transferred to the caller.

int json_object_extract_str_by_index(json_object_t *object, size_t index, str_t *value)

Note

The ownership of the returned value is transferred to the caller.

int json_object_extract_object_by_index(json_object_t *object, size_t index, json_object_t **value)

Note

The ownership of the returned value is transferred to the caller.

int json_object_extract_array_by_index(json_object_t *object, size_t index, json_array_t **value)

Note

The ownership of the returned value is transferred to the caller.

The json_object_extract_*_by_key extract the value from the object and sets *value with it. The object element is then set to JSON_NULL type. If the key is invalid or the value’s type at index doesn’t match, the function fails and both value and object are left untouched.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group EditorExtractKeyObject

Functions

int json_object_extract_bool_by_key(json_object_t *obj, char const *key, bool *value)
int json_object_extract_nb_by_key(json_object_t *obj, char const *key, int *value)
int json_object_extract_string_by_key(json_object_t *obj, char const *key, char **value)

Note

The ownership of the returned value is transferred to the caller.

int json_object_extract_str_by_key(json_object_t *obj, char const *key, str_t *value)

Note

The ownership of the returned value is transferred to the caller.

int json_object_extract_object_by_key(json_object_t *obj, char const *key, json_object_t **value)

Note

The ownership of the returned value is transferred to the caller.

int json_object_extract_array_by_key(json_object_t *obj, char const *key, json_array_t **value)

Note

The ownership of the returned value is transferred to the caller.

Generator

group GeneratorObject

Functions

int json_object_generate_to_fd(json_object_t const *obj, int fd, generator_setting_t const *setting)

The function generates obj to fd. fd won’t be closed after the generation of the object.

In case of failure json_errno will be set.

Note

If setting is null than the indent type will be set to SPACE and the indent size to 4.

Parameters
  • obj: Is a pointer to valid json_object_t

  • fd: A valid file descriptor

  • setting: Setting for the formatting

Return Value
  • JSON_EF: On failure

  • JSON_ES: On success

int json_object_generate_to_file(json_object_t const *obj, char const *filepath, generator_setting_t const *setting)

The function generates obj to the file specify by filepath.

The file at filepath is created if it doesn’t exist or truncated if it exist.

In case of failure json_errno will be set.

Note

If setting is null than the indent type will be set to SPACE and the indent size to 4.

Parameters
  • obj: Is a pointer to valid json_object_t

  • filepath: The file in which the object will be exported

  • setting: Setting for the formatting

Return Value
  • JSON_EF: On failure

  • JSON_ES: On success

int json_object_generate_to_string(json_object_t const *object, generator_setting_t const *setting, char **strptr)

The function generates obj to *strptr.

In case of failure json_errno will be set and *strptr will be left untouched.

Note

If setting is null than the indent type will be set to SPACE and the indent size to 4.

Parameters
  • obj: Is a pointer to valid json_object_t

  • strptr: A pointer of string which will be allocated to contain the exported object

  • setting: Setting for the formatting

Return Value
  • JSON_EF: On failure

  • JSON_ES: On success

Getters

The json_object_get_*_by_index get a value from the object at index and set *value at index. If the index is out of the bound or the type doesn’t match, the function fails.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group GettersIndexObject

Functions

int json_object_get_bool_by_index(json_object_t const *object, size_t index, bool *value)
int json_object_get_nb_by_index(json_object_t const *object, size_t index, int *value)
int json_object_get_str_by_index(json_object_t const *object, size_t index, str_t const **value)
int json_object_get_null_by_index(json_object_t const *object, size_t index, void const **value)
int json_object_get_object_by_index(json_object_t const *object, size_t index, json_object_t const **value)
int json_object_get_array_by_index(json_object_t const *object, size_t index, json_array_t const **value)

The json_object_get_*_by_key get the value which match the key from the object. If the key isn’t set in the object or the type doesn’t match, the function fails.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group GettersKeyObject

Functions

int json_object_get_bool_by_key(json_object_t const *obj, char const *key, bool *value)
int json_object_get_nb_by_key(json_object_t const *obj, char const *key, int *value)
int json_object_get_null_by_key(json_object_t const *obj, char const *key, void const **value)
int json_object_get_string_by_key(json_object_t const *obj, char const *key, char const **value)
int json_object_get_str_by_key(json_object_t const *obj, char const *key, str_t const **value)
int json_object_get_object_by_key(json_object_t const *obj, char const *key, json_object_t const **value)
int json_object_get_array_by_key(json_object_t const *obj, char const *key, json_array_t const **value)

Parser

group ParserObject

Functions

json_object_t *json_object_parse_from_fd(int fd)

The function parses a JSON object out of fd. When the end of the object is reached, the function returns the parsed object and let fd open.

In case of failure json_errno is set.

Note

json_errno is reset before the parsing of the object.

Return

On succes the function returns a pointer to a new json_object_t. On failure NULL is returned and json_errno is set.

json_object_t *json_object_parse_from_filepath(char const *filepath)

The functions parses a JSON object out of the file at filepath. If after the object there isn’t only whitespace characters, the function fails.

In case of failure json_errno is set.

Note

json_errno is reset before the parsing of the object.

Return

On succes the function returns a pointer to a new json_object_t. On failure NULL is returned and json_errno is set.

json_object_t *json_object_parse_from_str(char const *str, size_t *index)

The function parses a JSON object out of str. If the function succeed and index is not null, *index will be set with the index at which the parser stopped in str.

In case of failure json_errno is set.

Note

json_errno is reset before the parsing of the object.

Return

On succes the function returns a pointer to a new json_object_t. On failure NULL is returned and json_errno is set.

Set

The json_object_set_*_by_key sets value at key. If the key already exist the value is replace. Otherwise an element is created at the end of object.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group EditorSetKeyObject

Functions

int json_object_set_bool_by_key(json_object_t *obj, char const *key, bool value)
int json_object_set_nb_by_key(json_object_t *obj, char const *key, int value)
int json_object_set_str_dup_by_key(json_object_t *obj, char const *key, char const *value)
int json_object_set_str_by_key(json_object_t *obj, char const *key, char *value)

The function takes ownership of the value’s pointer.

int json_object_set_null_by_key(json_object_t *obj, char const *key)
int json_object_set_object_by_key(json_object_t *obj, char const *key, json_object_t *value)

The function takes ownership of the value’s pointer.

int json_object_set_array_by_key(json_object_t *obj, char const *key, json_array_t *value)

The function takes ownership of the value’s pointer.

Unset

The json_object_unset_element_by_key function unsets the element at key and remove it from the object. Return the number of unset elements.

group EditorUnsetObjectKey

Functions

size_t json_object_unset_element_by_key(json_object_t *obj, char const *key)

The json_object_unset_element_by_index function unsets the element at index and remove it from the object. Return the number of unset elements.

group EditorUnsetObjectIndex

Functions

size_t json_object_unset_element_by_index(json_object_t *obj, size_t index)

Array

Append

The json_array_append_* append value at the end of the array.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group EditorAppendArray

Functions

int json_array_append_bool(json_array_t *array, bool value)
int json_array_append_nb(json_array_t *array, int value)
int json_array_append_str_dup(json_array_t *array, char const *value)

The added value is a copy of value.

int json_array_append_str(json_array_t *array, char *value)

The function takes ownership of the value’s pointer.

int json_array_append_null(json_array_t *array)
int json_array_append_object(json_array_t *array, json_object_t *value)

The function takes ownership of the value’s pointer.

int json_array_append_array(json_array_t *array, json_array_t *value)

The function takes ownership of the value’s pointer.

Compare

group EditorCompareArray

Functions

bool json_array_compare(json_array_t const *array1, json_array_t const *array2)

The function compares array1 with array2. Equality is defined as follows:

  • json_array_elements of different type are never equal

  • json_array_elements of the same primitive type are equal if the c-representation of their value is equal

  • see json_object_compare for the equality criteria of the object

Return

true if the objects are equal, false otherewise.

Create

group EditorCreateArray

Functions

json_array_t *json_array_create(void)

The function creates an empty json_array_t.

Return

On success the function returns a pointer to a new json_array_t. On failure NULL is returned and json_errno is set to JSON_E_SYS_FAILURE.

Destroy

group EditorDestroyArray

#}

Functions

void json_array_destroy(json_array_t *array)

The function releases the allocated resources forarray.

Extract

The json_array_extract_*_by_index extract the value from the array and set *value with it. The array value is then set to JSON_NULL type. If the index is out of bound or the value’s type at index doesn’t match, the function fails and both value and array are left untouched.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group EditorExtractIndexArray

Functions

int json_array_extract_bool_by_index(json_array_t *array, size_t index, bool *value)
int json_array_extract_nb_by_index(json_array_t *array, size_t index, int *value)
int json_array_extract_string_by_index(json_array_t *array, size_t index, char **value)

Note

The ownership of the returned value is transferred to the caller.

int json_array_extract_str_by_index(json_array_t *array, size_t index, str_t *value)

Note

The ownership of the returned value is transferred to the caller.

int json_array_extract_object_by_index(json_array_t *array, size_t index, json_object_t **value)

Note

The ownership of the returned value is transferred to the caller.

int json_array_extract_array_by_index(json_array_t *array, size_t index, json_array_t **value)

Note

The ownership of the returned value is transferred to the caller.

Generator

group GeneratorArray

Functions

int json_array_generate_to_fd(json_array_t const *array, int fd, generator_setting_t const *setting)

The function generates array to fd. fd won’t be closed after the generation of the array.

In case of failure json_errno will be set.

Note

If setting is null than the indent type will be set to SPACE and the indent size to 4.

Parameters
  • array: Is a pointer to valid json_array_t

  • fd: A valid file descriptor

  • setting: Setting for the formatting

Return Value
  • JSON_EF: On failure

  • JSON_ES: On success

int json_array_generate_to_file(json_array_t const *array, char const *filepath, generator_setting_t const *setting)

The function generates array to the file specify by filepath.

The file at filepath is created if it doesn’t exist or truncated if it exist.

In case of failure json_errno will be set.

Note

If setting is null than the indent type will be set to SPACE and the indent size to 4.

Parameters
  • array: Is a pointer to valid json_array_t

  • filepath: The file in which the object will be exported

  • setting: Setting for the formatting

Return Value
  • JSON_EF: On failure

  • JSON_ES: On success

int json_array_generate_to_string(json_array_t const *array, generator_setting_t const *setting, char **strptr)

The function generates array to *strptr.

In case of failure json_errno will be set and *strptr will be left untouched.

Note

If setting is null than the indent type will be set to SPACE and the indent size to 4.

Parameters
  • array: Is a pointer to valid json_array_t

  • strptr: A pointer of string which will be allocated to contain the exported array

  • setting: Setting for the formatting

Return Value
  • JSON_EF: On failure

  • JSON_ES: On success

Getters

The json_array_get_*_by_index get a value from the array at index and set *value at index. If the index is out of the bound or the type doesn’t match, the function fails.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group GettersIndexArray

Functions

int json_array_get_bool_by_index(json_array_t const *array, size_t index, bool *value)
int json_array_get_nb_by_index(json_array_t const *array, size_t index, int *value)
int json_array_get_str_by_index(json_array_t const *array, size_t index, str_t const **value)
int json_array_get_null_by_index(json_array_t const *array, size_t index, void const **value)
int json_array_get_object_by_index(json_array_t const *array, size_t index, json_object_t const **value)
int json_array_get_array_by_index(json_array_t const *array, size_t index, json_array_t const **value)

Parser

group ParserArray

Functions

json_array_t *json_array_parse_from_fd(int fd)

The functions parses a JSON array out of fd. When the end of the array is reached, the function returns the parsed arrat and let fd open.

In case of failure json_errno is set.

Note

json_errno is reset before the parsing of the array.

Return

On succes the function returns a pointer to a new json_array_t. On failure NULL is returned and json_errno is set.

json_array_t *json_array_parse_from_filepath(char const *filepath)

The functions parses a JSON array out of the file at filepath. If after the array there isn’t only whitespace characters, the function fails.

In case of failure json_errno is set.

Note

json_errno is reset before the parsing of the array.

Return

On succes the function returns a pointer to a new json_array_t. On failure NULL is returned and json_errno is set.

json_array_t *json_array_parse_from_str(char const *str, size_t *index)

The function parses a JSON array out of str. If the function succeed and index is not null, *index will be set with the index at which the parser stopped in str.

In case of failure json_errno is set.

Note

json_errno is reset before the parsing of the array.

Return

On succes the function returns a pointer to a new json_array_t. On failure NULL is returned and json_errno is set.

Set

The json_array_set_*_by_index set the value at index in the array. If the index is out of the bound the function succeeds. Otherwise, the function fails and array if left untouched.

Return value:

  • On failure JSON_EF

  • On success JSON_ES

group EditorSetIndexArray

Functions

int json_array_set_bool_by_index(json_array_t *array, size_t index, bool value)
int json_array_set_nb_by_index(json_array_t *array, size_t index, int value)
int json_array_set_str_dup_by_index(json_array_t *array, size_t index, char const *value)

The value is duplicated if the function fails json_errno is set to JSON_E_SYS_FAILURE.

int json_array_set_str_by_index(json_array_t *array, size_t index, char *value)

The function takes ownership of the value’s pointer.

int json_array_set_null_by_index(json_array_t *array, size_t index)
int json_array_set_object_by_index(json_array_t *array, size_t index, json_object_t *value)

The function takes ownership of the value’s pointer.

int json_array_set_array_by_index(json_array_t *array, size_t index, json_array_t *value)

The function takes ownership of the value’s pointer.

Unset

The json_array_unset_element_by_index function unsets the element at index and remove it from the array. Return the number of unset element.

group EditorUnsetArrayIndex

Functions

int json_array_unset_element_by_index(json_array_t *array, size_t index)

The json_array_unset_element_by_value_* functions unset all elements which match value and remove them from the array. Return the number of unset element(s).

group EditorUnsetArrayValue

Functions

int json_array_unset_elements_by_value_bool(json_array_t *array, bool value)
int json_array_unset_elements_by_value_nb(json_array_t *array, int value)
int json_array_unset_elements_by_value_str(json_array_t *array, str_t const *value)
int json_array_unset_elements_by_null(json_array_t *array)
int json_array_unset_elements_by_value_object(json_array_t *array, json_object_t *value)
int json_array_unset_elements_by_value_array(json_array_t *array, json_array_t *value)