Json utility module interface header file. More...
#include "mcl/mcl_common.h"
Go to the source code of this file.
Typedefs | |
typedef struct mcl_json_t | mcl_json_t |
This struct is used for json handling. More... | |
Enumerations | |
enum | E_MCL_JSON_TYPE { MCL_JSON_ARRAY, MCL_JSON_OBJECT } |
Json type definitions. More... | |
Functions | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_initialize (E_MCL_JSON_TYPE json_type, mcl_json_t **root) |
This function initializes the given root json. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_start_array (mcl_json_t *root, const char *array_name, mcl_json_t **json_array) |
This function creates an array in root . More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_get_array_item (mcl_json_t *array, int index, mcl_json_t **item) |
This function gets the item at given index from array . More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_get_array_size (mcl_json_t *array, mcl_size_t *size) |
This function returns the size of array . More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_start_object (mcl_json_t *root, const char *object_name, mcl_json_t **json_object) |
This function creates an object in root . More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_string (mcl_json_t *root, const char *object_name, const char *object_value) |
This function adds string to root which can be object or array. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_uint (mcl_json_t *root, const char *object_name, const mcl_size_t number) |
This function adds integer number to root which can be object or array. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_float (mcl_json_t *root, const char *object_name, const float number) |
This function adds floating number to root . More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_double (mcl_json_t *root, const char *object_name, const double number) |
This function adds double number to root which can be object or array. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_bool (mcl_json_t *root, const char *object_name, const mcl_bool_t bool_value) |
This function adds bool_value to root which can be object or array. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_null (mcl_json_t *root, const char *object_name) |
This function adds null to root which can be object or array. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_object (mcl_json_t *root, const char *object_name, mcl_json_t *object) |
This function adds object to root . More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_add_item_to_array (mcl_json_t *root, mcl_json_t *object) |
This function adds object to root array. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_get_object_item (mcl_json_t *json_parent, const char *child_name, mcl_json_t **json_child) |
This function gives the value of json_child object, when the child_name in json_parent object is given. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_has_child (mcl_json_t *root, mcl_bool_t *result) |
This function checks whether root object has child object or not. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_get_number_value (mcl_json_t *json, mcl_int32_t *number_value) |
This function gets the number value of a given json object. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_get_double_value (mcl_json_t *json, double *double_value) |
This function gets the double value of a given json object. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_get_bool_value (mcl_json_t *json, mcl_bool_t *bool_value) |
This function gets the boolean value of a given json object. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_get_string (mcl_json_t *json_item, char **string_value) |
This function gets the string value of a given json object. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_to_string (mcl_json_t *root, char **json_string) |
This function gives the string of root in json format. More... | |
MCL_EXPORT E_MCL_ERROR_CODE | mcl_json_util_parse (const char *json_string, mcl_json_t **root) |
This function parses the given string to the given json object. More... | |
MCL_EXPORT void | mcl_json_util_finish_array (mcl_json_t **json_array) |
This function destroys json_array data struct. But the array still exists in root json object. More... | |
MCL_EXPORT void | mcl_json_util_finish_object (mcl_json_t **json_object) |
This function destroys json_object data struct. But the object still exists in root json object. More... | |
MCL_EXPORT void | mcl_json_util_destroy (mcl_json_t **root) |
This function destroys root . More... | |
Json utility module interface header file.
Definition in file mcl_json_util.h.
typedef struct mcl_json_t mcl_json_t |
This struct is used for json handling.
Definition at line 29 of file mcl_json_util.h.
enum E_MCL_JSON_TYPE |
Json type definitions.
Enumerator | |
---|---|
MCL_JSON_ARRAY |
Json array. |
MCL_JSON_OBJECT |
Json object. |
Definition at line 34 of file mcl_json_util.h.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_bool | ( | mcl_json_t * | root, |
const char * | object_name, | ||
const mcl_bool_t | bool_value | ||
) |
This function adds bool_value
to root
which can be object or array.
[in] | root | Root json. It can be object or array. |
[in] | object_name | Name of the bool value which is going to be added to root . |
[in] | bool_value | Bool value to be added to root . |
root
is NULL. object_name
is already used in root
as object name. root
type is array and object_name
is not null, or root
type is object and object_name
is null. Definition at line 392 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_bool().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_double | ( | mcl_json_t * | root, |
const char * | object_name, | ||
const double | number | ||
) |
This function adds double number to root
which can be object or array.
[in] | root | Root json. It can be object or array. |
[in] | object_name | Name of the name/value pair which is going to be added to root . |
[in] | number | Value of the name/value pair which is going to be added to root . |
root
is NULL. object_name
is already used in root
as object name. root
type is array and object_name
is not null, or root
type is object and object_name
is null. Definition at line 344 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_double().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_float | ( | mcl_json_t * | root, |
const char * | object_name, | ||
const float | number | ||
) |
This function adds floating number to root
.
[in] | root | Root json object. |
[in] | object_name | Name of the name/value pair which is going to be added to root . |
[in] | number | Value of the name/value pair which is going to be added to root . |
root
or object_name
is NULL. Definition at line 319 of file json_util.c.
References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_float().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_item_to_array | ( | mcl_json_t * | root, |
mcl_json_t * | object | ||
) |
This function adds object
to root
array.
[in] | root | Root json array. |
[in] | object | object which is going to be added to root array. |
root
, object_name
or object
is NULL. Definition at line 527 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_add_item_to_array(), and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_null | ( | mcl_json_t * | root, |
const char * | object_name | ||
) |
This function adds null to root
which can be object or array.
[in] | root | Root json. It can be object or array. |
[in] | object_name | Name of the null value which is going to be added to root . |
root
is NULL. object_name
is already used in root
as object name. root
type is array and object_name
is not null, or root
type is object and object_name
is null. Definition at line 440 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_null().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_object | ( | mcl_json_t * | root, |
const char * | object_name, | ||
mcl_json_t * | object | ||
) |
This function adds object
to root
.
[in] | root | Root json object. |
[in] | object_name | Name of object which is going to be going to be added to root . |
[in] | object | object which is going to be added to root . |
root
, object_name
or object
is NULL. object_name
is already used in root
as object name. Definition at line 488 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_add_object(), and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_string | ( | mcl_json_t * | root, |
const char * | object_name, | ||
const char * | object_value | ||
) |
This function adds string to root
which can be object or array.
root
is array, object_name
must be null.[in] | root | Root json. It can be object or array. |
[in] | object_name | Name of the name/value pair which is going to be added to root . |
[in] | object_value | Value of the name/value pair which is going to be added to root . |
root
or object_value
is NULL. object_name
is already used in root
as object name. root
type is array and object_name
is not null, or root
type is object and object_name
is null. Definition at line 222 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_string().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_add_uint | ( | mcl_json_t * | root, |
const char * | object_name, | ||
const mcl_size_t | number | ||
) |
This function adds integer number to root
which can be object or array.
root
is array, object_name
must be null.[in] | root | Root json. It can be object or array. |
[in] | object_name | Name of the name/value pair which is going to be added to root . |
[in] | number | Value of the name/value pair which is going to be added to root . |
root
is NULL. object_name
is already used in root
as object name. root
type is array and object_name
is not null, or root
type is object and object_name
is null. Definition at line 271 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_uint().
MCL_EXPORT void mcl_json_util_destroy | ( | mcl_json_t ** | root | ) |
This function destroys root
.
root
is destroyed, all child json objects in root
are also destroyed.[out] | root | Root json object. |
Definition at line 854 of file json_util.c.
References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_destroy().
MCL_EXPORT void mcl_json_util_finish_array | ( | mcl_json_t ** | json_array | ) |
This function destroys json_array
data struct. But the array still exists in root json object.
json_array
from root, mcl_json_util_destroy must be called for root json object.[out] | json_array | Json array which exists in root . |
Definition at line 818 of file json_util.c.
References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_finish_array().
MCL_EXPORT void mcl_json_util_finish_object | ( | mcl_json_t ** | json_object | ) |
This function destroys json_object
data struct. But the object still exists in root json object.
json_object
from root, mcl_json_util_destroy must be called for root json object.[out] | json_object | Json object which exists in root . |
Definition at line 836 of file json_util.c.
References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_finish_object().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_array_item | ( | mcl_json_t * | array, |
int | index, | ||
mcl_json_t ** | item | ||
) |
This function gets the item at given index from array
.
[in] | array | Array json object. |
[in] | index | Index of the item to get from array . |
[out] | item | Result json object item.New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space using MCL_FREE(). |
Definition at line 126 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_get_array_item().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_array_size | ( | mcl_json_t * | array, |
mcl_size_t * | size | ||
) |
This function returns the size of array
.
[in] | array | Array json object. |
[out] | size | Size of array . |
Definition at line 160 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_get_array_size(), and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_bool_value | ( | mcl_json_t * | json, |
mcl_bool_t * | bool_value | ||
) |
This function gets the boolean value of a given json object.
[in] | json | Root object of bool_value . |
[in] | bool_value | Boolean value of json . |
json
or bool_value
is NULL. Definition at line 660 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_get_bool_value(), and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_double_value | ( | mcl_json_t * | json, |
double * | double_value | ||
) |
This function gets the double value of a given json object.
[in] | json | Root object of double_value . |
[in] | double_value | Value of json . |
json
or double_value
is NULL. Definition at line 638 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_get_double_value(), and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_number_value | ( | mcl_json_t * | json, |
mcl_int32_t * | number_value | ||
) |
This function gets the number value of a given json object.
[in] | json | Root object of number_value . |
[in] | number_value | Value of json . |
json
or number_value
is NULL. Definition at line 616 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_get_number_value(), and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_object_item | ( | mcl_json_t * | json_parent, |
const char * | child_name, | ||
mcl_json_t ** | json_child | ||
) |
This function gives the value of json_child
object, when the child_name
in json_parent
object is given.
[in] | json_parent | Root json object of json_child . |
[in] | child_name | Name of the json_child object. |
[out] | json_child | The json object which is going to be received. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space using MCL_FREE(). |
json_parent
, child_name
or json_child
is NULL. json_child
doesn't exist in json_parent
. Definition at line 549 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_get_object_item().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_get_string | ( | mcl_json_t * | json_item, |
char ** | string_value | ||
) |
This function gets the string value of a given json object.
[in] | json_item | Root object of string_value . |
[in] | string_value | String value of json_item . New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space. |
json
or string_value
is NULL. Definition at line 689 of file json_util.c.
References ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, json_util_get_string(), MCL_FREE, MCL_NULL, and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_has_child | ( | mcl_json_t * | root, |
mcl_bool_t * | result | ||
) |
This function checks whether root object has child object or not.
[in] | root | Json object which is going to be checked whether it has child or not. |
[out] | result | This bool value is going to be made true, if @ root has child. Otherwise it is false. |
root
or result
is NULL. Definition at line 587 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_has_child(), and MCL_OK.
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_initialize | ( | E_MCL_JSON_TYPE | json_type, |
mcl_json_t ** | root | ||
) |
This function initializes the given root
json.
[in] | json_type | Type of the json. |
[out] | root | Root json. |
root
is NULL. Definition at line 39 of file json_util.c.
References _convert_mcl_json_type_to_json_type(), ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_initialize().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_parse | ( | const char * | json_string, |
mcl_json_t ** | root | ||
) |
This function parses the given string to the given json object.
[in] | json_string | String in json format. This given string must be null terminated. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space. |
[out] | root | json_string is going to be parsed to this root object. |
json_string
or root
is NULL. Definition at line 748 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_parse().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_start_array | ( | mcl_json_t * | root, |
const char * | array_name, | ||
mcl_json_t ** | json_array | ||
) |
This function creates an array in root
.
[in] | root | Root json object. |
[in] | array_name | Name of the array which is going to be created in root . |
[out] | json_array | Json array which is going to be created in root . |
root
, array_name
or json_array
is NULL. array_name
is already used in root
as object name. Definition at line 84 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_start_array().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_start_object | ( | mcl_json_t * | root, |
const char * | object_name, | ||
mcl_json_t ** | json_object | ||
) |
This function creates an object in root
.
[in] | root | Root json object. |
[in] | object_name | Name of the object which is going to be created in root . |
[out] | json_object | Json object which is going to be created in root . |
root
, object_name
or json_object
is NULL. object_name
is already used in root
as object name. Definition at line 182 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_start_object().
MCL_EXPORT E_MCL_ERROR_CODE mcl_json_util_to_string | ( | mcl_json_t * | root, |
char ** | json_string | ||
) |
This function gives the string of root
in json format.
[in] | root | Root json object. |
[out] | json_string | The string of root in json format. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space. |
root
or json_string
is NULL. Definition at line 722 of file json_util.c.
References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_to_string().