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.
-
int
Compare¶
-
group
EditorCompareObject Functions
-
bool
json_object_compare(json_object_t const *obj1, json_object_t const *obj2)¶ The function compares
obj1withobj2. 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.
-
bool
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 andjson_errnois set to JSON_E_SYS_FAILURE.
-
json_object_t *
Destroy¶
-
group
EditorDestroyObject Functions
-
void
json_object_destroy(json_object_t *obj)¶ The function releases the allocated resources for
obj.
-
void
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.
-
int
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.
-
int
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
objtofd.fdwon’t be closed after the generation of the object.In case of failure
json_errnowill be set.- Note
If
settingis null than the indent type will be set to SPACE and the indent size to 4.- Parameters
obj: Is a pointer to validjson_object_tfd: A valid file descriptorsetting: Setting for the formatting
- Return Value
JSON_EF: On failureJSON_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
objto the file specify byfilepath.The file at
filepathis created if it doesn’t exist or truncated if it exist.In case of failure
json_errnowill be set.- Note
If
settingis null than the indent type will be set to SPACE and the indent size to 4.- Parameters
obj: Is a pointer to validjson_object_tfilepath: The file in which the object will be exportedsetting: Setting for the formatting
- Return Value
JSON_EF: On failureJSON_ES: On success
-
int
json_object_generate_to_string(json_object_t const *object, generator_setting_t const *setting, char **strptr)¶ The function generates
objto*strptr.In case of failure
json_errnowill 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 validjson_object_tstrptr: A pointer of string which will be allocated to contain the exported objectsetting: Setting for the formatting
- Return Value
JSON_EF: On failureJSON_ES: On success
-
int
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)¶
-
int
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)¶
-
int
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 letfdopen.In case of failure
json_errnois set.- Note
json_errnois 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 andjson_errnois 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_errnois set.- Note
json_errnois 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 andjson_errnois 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 andindexis not null,*indexwill be set with theindexat which the parser stopped instr.In case of failure
json_errnois set.- Note
json_errnois 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 andjson_errnois set.
-
json_object_t *
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.
-
int
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)¶
-
size_t
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)¶
-
size_t
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.
-
int
Compare¶
-
group
EditorCompareArray Functions
-
bool
json_array_compare(json_array_t const *array1, json_array_t const *array2)¶ The function compares
array1witharray2. 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.
-
bool
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 andjson_errnois set to JSON_E_SYS_FAILURE.
-
json_array_t *
Destroy¶
-
group
EditorDestroyArray #}
Functions
-
void
json_array_destroy(json_array_t *array)¶ The function releases the allocated resources for
array.
-
void
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_EFOn 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.
-
int
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
arraytofd.fdwon’t be closed after the generation of the array.In case of failure
json_errnowill be set.- Note
If
settingis null than the indent type will be set to SPACE and the indent size to 4.- Parameters
array: Is a pointer to validjson_array_tfd: A valid file descriptorsetting: Setting for the formatting
- Return Value
JSON_EF: On failureJSON_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
arrayto the file specify byfilepath.The file at
filepathis created if it doesn’t exist or truncated if it exist.In case of failure
json_errnowill be set.- Note
If
settingis null than the indent type will be set to SPACE and the indent size to 4.- Parameters
array: Is a pointer to validjson_array_tfilepath: The file in which the object will be exportedsetting: Setting for the formatting
- Return Value
JSON_EF: On failureJSON_ES: On success
-
int
json_array_generate_to_string(json_array_t const *array, generator_setting_t const *setting, char **strptr)¶ The function generates
arrayto*strptr.In case of failure
json_errnowill 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 validjson_array_tstrptr: A pointer of string which will be allocated to contain the exported arraysetting: Setting for the formatting
- Return Value
JSON_EF: On failureJSON_ES: On success
-
int
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)¶
-
int
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 letfdopen.In case of failure
json_errnois set.- Note
json_errnois 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 andjson_errnois 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_errnois set.- Note
json_errnois 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 andjson_errnois 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 andindexis not null,*indexwill be set with theindexat which the parser stopped instr.In case of failure
json_errnois set.- Note
json_errnois 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 andjson_errnois set.
-
json_array_t *
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.
-
int
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)¶
-
int
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)¶
-
int