json_util.c File Reference

Json util module implementation file. More...

#include "cJSON/cJSON.h"
#include "json_util.h"
#include "mcl/mcl_json_util.h"
#include "definitions.h"
#include "log_util.h"
#include "memory.h"
#include "string_util.h"
Include dependency graph for json_util.c:

Go to the source code of this file.

Functions

static void _finish_json_item (json_t **json_item)
 
static E_JSON_TYPE _convert_mcl_json_type_to_json_type (E_MCL_JSON_TYPE mcl_json_type)
 
void json_util_initialize_json_library ()
 This function initializes json library. More...
 
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...
 
E_MCL_ERROR_CODE json_util_initialize (E_JSON_TYPE json_type, json_t **root)
 This function initializes the given root json. More...
 
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...
 
E_MCL_ERROR_CODE json_util_start_array (json_t *root, const char *array_name, json_t **json_array)
 This function creates an array in root. More...
 
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...
 
E_MCL_ERROR_CODE json_util_get_array_item (json_t *array, int index, json_t **item)
 This function gets the item at given index from array. More...
 
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...
 
void json_util_get_array_size (json_t *array, mcl_size_t *size)
 This function returns the size of array. More...
 
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...
 
E_MCL_ERROR_CODE json_util_start_object (json_t *root, const char *object_name, json_t **json_object)
 This function creates an object in root. More...
 
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...
 
E_MCL_ERROR_CODE json_util_add_string (json_t *root, const char *object_name, const char *object_value)
 This function adds string to root which can be object or array. More...
 
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...
 
E_MCL_ERROR_CODE json_util_add_uint (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...
 
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...
 
E_MCL_ERROR_CODE json_util_add_float (json_t *root, const char *object_name, const float number)
 This function adds floating number to root. More...
 
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...
 
E_MCL_ERROR_CODE json_util_add_double (json_t *root, const char *object_name, const double number)
 This function adds double number to root which can be object or array. More...
 
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...
 
E_MCL_ERROR_CODE json_util_add_bool (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...
 
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...
 
E_MCL_ERROR_CODE json_util_add_null (json_t *root, const char *object_name)
 This function adds null to root which can be object or array. More...
 
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...
 
E_MCL_ERROR_CODE json_util_add_object (json_t *root, const char *object_name, json_t *object)
 This function adds object to root. More...
 
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...
 
void json_util_add_item_to_array (json_t *root, json_t *object)
 This function adds object to root array. More...
 
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...
 
E_MCL_ERROR_CODE json_util_get_object_item (json_t *json_parent, const char *child_name, json_t **json_child)
 This function gives the value of json_child object, when the child_name in json_parent object is given. More...
 
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_bool_t json_util_has_child (json_t *root)
 This function checks whether root object has child object or not. More...
 
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...
 
void json_util_get_number_value (json_t *json, mcl_int32_t *number_value)
 This function gets the number value of a given json object. More...
 
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...
 
void json_util_get_double_value (json_t *json, double *double_value)
 This function gets the double value of a given json object. More...
 
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...
 
void json_util_get_bool_value (json_t *json, mcl_bool_t *bool_value)
 This function gets the boolean value of a given json object. More...
 
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...
 
E_MCL_ERROR_CODE json_util_get_string (json_t *json_item, string_t **string_value)
 This function gets the string value of a given json object. More...
 
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...
 
E_MCL_ERROR_CODE json_util_to_string (json_t *root, char **json_string)
 This function gives the string of root in json format. More...
 
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...
 
E_MCL_ERROR_CODE json_util_parse (const char *json_string, json_t **root)
 This function parses the given string to the given json object. More...
 
E_MCL_ERROR_CODE json_util_parse_with_size (const char *json_string, mcl_size_t size, json_t **root)
 This function parses the given string to the given json object. More...
 
E_MCL_ERROR_CODE json_util_duplicate (const json_t *source_json, mcl_bool_t with_children, json_t **duplicated_json)
 This function duplicates source_json as duplicated_json. More...
 
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...
 
void json_util_finish_array (json_t **json_array)
 This function destroys json_array data struct. But the array still exists in root json object. More...
 
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...
 
void json_util_finish_object (json_t **json_object)
 This function destroys json_object data struct. But the object still exists in root json object. More...
 
void mcl_json_util_destroy (mcl_json_t **root)
 This function destroys root. More...
 
void json_util_destroy (json_t **root)
 This function destroys root. More...
 

Variables

static cJSON_Hooks cjson_hooks
 

Detailed Description

Json util module implementation file.


Date
Feb 22, 2017

Definition in file json_util.c.

Function Documentation

static E_JSON_TYPE _convert_mcl_json_type_to_json_type ( E_MCL_JSON_TYPE  mcl_json_type)
static

Definition at line 888 of file json_util.c.

References JSON_ARRAY, JSON_NULL, JSON_OBJECT, MCL_JSON_ARRAY, MCL_JSON_OBJECT, MCL_VERBOSE, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_initialize().

Here is the caller graph for this function:

static void _finish_json_item ( json_t **  json_item)
static

Definition at line 876 of file json_util.c.

References MCL_FREE, MCL_NULL, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by json_util_finish_array(), and json_util_finish_object().

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_add_bool ( 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.

Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the bool value which is going to be added to root.
[in]bool_valueBool value to be added to root.
Returns

Definition at line 406 of file json_util.c.

References ASSERT_CODE_MESSAGE, json_util_get_object_item(), MCL_FREE, MCL_INVALID_PARAMETER, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_add_bool().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_add_double ( json_t root,
const char *  object_name,
const double  number 
)

This function adds double number to root which can be object or array.

Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]numberValue of the name/value pair which is going to be added to root.
Returns

Definition at line 358 of file json_util.c.

References ASSERT_CODE_MESSAGE, json_util_get_object_item(), MCL_FREE, MCL_INVALID_PARAMETER, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _create_self_issued_jwt_payload(), and mcl_json_util_add_double().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_add_float ( json_t root,
const char *  object_name,
const float  number 
)

This function adds floating number to root.

Warning
If cJson library is used, this function is not supported.
Parameters
[in]rootRoot json object.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]numberValue of the name/value pair which is going to be added to root.
Returns

Definition at line 329 of file json_util.c.

References MCL_OPERATION_IS_NOT_SUPPORTED, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_add_float().

Here is the caller graph for this function:

void json_util_add_item_to_array ( json_t root,
json_t object 
)

This function adds object to root array.

Parameters
[in]rootRoot json array.
[in]objectobject which is going to be added to root array.

Definition at line 540 of file json_util.c.

References json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_event(), _add_key_to_keys_array(), _add_time_series_payload_values_objects(), _add_time_series_value_set(), and mcl_json_util_add_item_to_array().

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_add_null ( json_t root,
const char *  object_name 
)

This function adds null to root which can be object or array.

Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the null value which is going to be added to root.
Returns

Definition at line 454 of file json_util.c.

References ASSERT_CODE_MESSAGE, json_util_get_object_item(), MCL_FREE, MCL_INVALID_PARAMETER, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_add_null().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_add_object ( json_t root,
const char *  object_name,
json_t object 
)

This function adds object to root.

Parameters
[in]rootRoot json object.
[in]object_nameName of object which is going to be going to be added to root.
[in]objectobject which is going to be added to root.
Returns

Definition at line 504 of file json_util.c.

References ASSERT_CODE_MESSAGE, json_util_get_object_item(), MCL_FREE, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_event(), _add_item_meta_details(), _add_item_meta_payload_details(), and mcl_json_util_add_object().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_add_string ( json_t root,
const char *  object_name,
const char *  object_value 
)

This function adds string to root which can be object or array.

Note
if root is array, object_name must be null.
Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]object_valueValue of the name/value pair which is going to be added to root.
Returns

Definition at line 237 of file json_util.c.

References ASSERT_CODE_MESSAGE, json_util_get_object_item(), MCL_FREE, MCL_INVALID_PARAMETER, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_event(), _add_item_meta_payload(), _add_schema_to_jwt(), _add_string_field_to_object(), _add_time_series_payload_values_objects(), _add_time_series_value_set(), _compose_rsa_key_rotation_json(), _compose_rsa_onboarding_json(), _create_self_issued_jwt_header(), _create_self_issued_jwt_payload(), json_from_data_source_configuration_payload(), and mcl_json_util_add_string().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_add_uint ( 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.

Note
if root is array, object_name must be null.
Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]numberValue of the name/value pair which is going to be added to root.
Returns

Definition at line 285 of file json_util.c.

References ASSERT_CODE_MESSAGE, json_util_get_object_item(), MCL_FREE, MCL_INVALID_PARAMETER, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_event(), and mcl_json_util_add_uint().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_duplicate ( const json_t source_json,
mcl_bool_t  with_children,
json_t **  duplicated_json 
)

This function duplicates source_json as duplicated_json.

Parameters
[in]source_jsonJson object to be duplicated.
[in]with_childrenIf it is true, duplicate with children. Otherwise, only root is duplicated.
[out]duplicated_jsonDuplicated json from source_json.
Returns

Definition at line 805 of file json_util.c.

References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_event(), _add_item_meta_payload_details(), mcl_custom_data_set_meta_details(), mcl_data_source_configuration_add_data_point(), mcl_data_source_configuration_add_data_source(), and mcl_event_set_option().

Here is the caller graph for this function:

void json_util_finish_array ( json_t **  json_array)

This function destroys json_array data struct. But the array still exists in root json object.

Note
To remove json_array from root, mcl_json_util_destroy must be called for root json object.
Parameters
[out]json_arrayJson array which exists in root.

Definition at line 827 of file json_util.c.

References _finish_json_item(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_schema_to_jwt(), _add_time_series_payload_values_array(), and mcl_json_util_finish_array().

Here is the call graph for this function:

Here is the caller graph for this function:

void json_util_finish_object ( json_t **  json_object)

This function destroys json_object data struct. But the object still exists in root json object.

Note
To remove json_object from root, mcl_json_util_destroy must be called for root json object.
Parameters
[out]json_objectJson object which exists in root.

Definition at line 845 of file json_util.c.

References _finish_json_item(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_event(), _add_item_meta_details(), _add_item_meta_payload(), _add_item_meta_payload_details(), _add_time_series_payload_values_objects(), _add_time_series_value_set(), _compose_rsa_key_rotation_json(), _compose_rsa_onboarding_json(), and mcl_json_util_finish_object().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_get_array_item ( json_t array,
int  index,
json_t **  item 
)

This function gets the item at given index from array.

Parameters
[in]arrayArray json object.
[in]indexIndex of the item to get from array.
[out]itemResult json object item.
Returns

Definition at line 141 of file json_util.c.

References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, MCL_FAIL, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_TRUE, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_get_array_item().

Here is the caller graph for this function:

void json_util_get_array_size ( json_t array,
mcl_size_t size 
)

This function returns the size of array.

Parameters
[in]arrayArray json object.
[out]sizeSize of array.
Returns

Definition at line 173 of file json_util.c.

References json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_get_array_size().

Here is the caller graph for this function:

void json_util_get_bool_value ( json_t json,
mcl_bool_t bool_value 
)

This function gets the boolean value of a given json object.

Parameters
[in]jsonRoot object of bool_value.
[in]bool_valueValue of json.

Definition at line 673 of file json_util.c.

References MCL_FALSE, MCL_TRUE, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_get_bool_value().

Here is the caller graph for this function:

void json_util_get_double_value ( json_t json,
double *  double_value 
)

This function gets the double value of a given json object.

Parameters
[in]jsonRoot object of double_value.
[in]double_valueValue of json.

Definition at line 651 of file json_util.c.

References json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_get_double_value().

Here is the caller graph for this function:

void json_util_get_number_value ( json_t json,
mcl_int32_t number_value 
)

This function gets the number value of a given json object.

Parameters
[in]jsonRoot object of number_value.
[in]number_valueValue of json.

Definition at line 629 of file json_util.c.

References json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_get_number_value().

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_get_object_item ( json_t json_parent,
const char *  child_name,
json_t **  json_child 
)

This function gives the value of json_child object, when the child_name in json_parent object is given.

Parameters
[in]json_parentRoot json object of json_child.
[in]child_nameName of the json_child object.
[out]json_childThe 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 of json_child with MCL_FREE(*json_child).
Returns

Definition at line 565 of file json_util.c.

References ASSERT_CODE_MESSAGE, MCL_FREE, MCL_NEW, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _process_registration_response_rsa_3072(), _process_registration_response_shared_secret(), http_processor_get_access_token(), json_util_add_bool(), json_util_add_double(), json_util_add_null(), json_util_add_object(), json_util_add_string(), json_util_add_uint(), json_util_start_array(), json_util_start_object(), and mcl_json_util_get_object_item().

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_get_string ( json_t json_item,
string_t **  string_value 
)

This function gets the string value of a given json object.

Parameters
[in]json_itemRoot object of string_value.
[in]string_valueString value of json_item. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space.
Returns

Definition at line 711 of file json_util.c.

References ASSERT_CODE_MESSAGE, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, string_initialize_new(), VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _process_registration_response_rsa_3072(), _process_registration_response_shared_secret(), http_processor_get_access_token(), and mcl_json_util_get_string().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_bool_t json_util_has_child ( json_t root)

This function checks whether root object has child object or not.

Parameters
[in]rootJson object which is going to be checked whether it has child or not.
Returns
  • MCL_TRUE if provided root has child.
  • MCL_FALSE if provided root does not have any child.

Definition at line 600 of file json_util.c.

References MCL_FALSE, MCL_NULL, MCL_TRUE, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_item_meta_details(), _add_item_meta_payload_details(), and mcl_json_util_has_child().

Here is the caller graph for this function:

void json_util_initialize_json_library ( )

This function initializes json library.

Supplying malloc, realloc and free functions to cJSON is performed in this function.

Definition at line 28 of file json_util.c.

References cjson_hooks, DEBUG_ENTRY, DEBUG_LEAVE, memory_free(), and memory_malloc().

Referenced by http_processor_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_parse ( const char *  json_string,
json_t **  root 
)

This function parses the given string to the given json object.

Parameters
[in]json_stringString in json format. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space.
[out]rootjson_string is going to be parsed to this root object.
Returns

Definition at line 763 of file json_util.c.

References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, MCL_FAIL, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by mcl_json_util_parse().

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_parse_with_size ( const char *  json_string,
mcl_size_t  size,
json_t **  root 
)

This function parses the given string to the given json object.

Parameters
[in]json_stringString in json format. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space.
[in]sizeSize of the buffer. If json_string is null terminated, size must be zero. Otherwise size value must be size of json_string.
[out]rootjson_string is going to be parsed to this root object.
Returns

Definition at line 777 of file json_util.c.

References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, MCL_FAIL, MCL_FREE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _process_registration_response_rsa_3072(), _process_registration_response_shared_secret(), and http_processor_get_access_token().

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_start_array ( json_t root,
const char *  array_name,
json_t **  json_array 
)

This function creates an array in root.

Parameters
[in]rootRoot json object.
[in]array_nameName of the array which is going to be created in root.
[out]json_arrayJson array which is going to be created in root.
Returns

Definition at line 100 of file json_util.c.

References ASSERT_CODE_MESSAGE, JSON_ARRAY, json_util_get_object_item(), json_util_initialize(), MCL_FREE, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_data_source_configuration_data_points(), _add_data_source_configuration_data_sources(), _add_schema_to_jwt(), _add_time_series_payload_values_array(), _compose_rsa_key_rotation_json(), _compose_rsa_onboarding_json(), and mcl_json_util_start_array().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_start_object ( json_t root,
const char *  object_name,
json_t **  json_object 
)

This function creates an object in root.

Parameters
[in]rootRoot json object.
[in]object_nameName of the object which is going to be created in root.
[out]json_objectJson object which is going to be created in root.
Returns

Definition at line 198 of file json_util.c.

References ASSERT_CODE_MESSAGE, JSON_OBJECT, json_util_get_object_item(), json_util_initialize(), MCL_FREE, MCL_JSON_NAME_DUPLICATION, MCL_NON_EXISTING_JSON_CHILD, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _add_item_meta_payload(), _compose_rsa_key_rotation_json(), _compose_rsa_onboarding_json(), and mcl_json_util_start_object().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE json_util_to_string ( json_t root,
char **  json_string 
)

This function gives the string of root in json format.

Parameters
[in]rootRoot json object.
[out]json_stringThe string of root in json format.
Returns
  • MCL_OK in case of success.
  • MCL_FAIL either the given json is invalid or memory can not be allocated for root.

Definition at line 737 of file json_util.c.

References ASSERT_CODE_MESSAGE, MCL_FAIL, MCL_NULL, MCL_OK, json_t::root_handle, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _compose_rsa_key_rotation_json(), _compose_rsa_onboarding_json(), json_from_data_source_configuration_payload(), json_from_event_payload(), json_from_item_meta(), json_from_time_series_payload(), jwt_get_token(), and mcl_json_util_to_string().

Here is the caller graph for this function:

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.

Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the bool value which is going to be added to root.
[in]bool_valueBool value to be added to root.
Returns

Definition at line 392 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_bool().

Here is the call graph for this function:

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.

Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]numberValue of the name/value pair which is going to be added to root.
Returns

Definition at line 344 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_double().

Here is the call graph for this function:

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.

Warning
If cJson library is used, this function is not supported.
Parameters
[in]rootRoot json object.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]numberValue of the name/value pair which is going to be added to root.
Returns

Definition at line 319 of file json_util.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_float().

Here is the call graph for this function:

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.

Parameters
[in]rootRoot json array.
[in]objectobject which is going to be added to root array.
Returns

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.

Here is the call graph for this function:

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.

Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the null value which is going to be added to root.
Returns

Definition at line 440 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_null().

Here is the call graph for this function:

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.

Parameters
[in]rootRoot json object.
[in]object_nameName of object which is going to be going to be added to root.
[in]objectobject which is going to be added to root.
Returns

Definition at line 488 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_add_object(), and MCL_OK.

Here is the call graph for this function:

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.

Note
if root is array, object_name must be null.
Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]object_valueValue of the name/value pair which is going to be added to root.
Returns

Definition at line 222 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_string().

Here is the call graph for this function:

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.

Note
if root is array, object_name must be null.
Parameters
[in]rootRoot json. It can be object or array.
[in]object_nameName of the name/value pair which is going to be added to root.
[in]numberValue of the name/value pair which is going to be added to root.
Returns

Definition at line 271 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_add_uint().

Here is the call graph for this function:

void mcl_json_util_destroy ( mcl_json_t **  root)

This function destroys root.

Note
If root is destroyed, all child json objects in root are also destroyed.
Parameters
[out]rootRoot json object.

Definition at line 854 of file json_util.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_destroy().

Here is the call graph for this function:

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.

Note
To remove json_array from root, mcl_json_util_destroy must be called for root json object.
Parameters
[out]json_arrayJson array which exists in root.

Definition at line 818 of file json_util.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_finish_array().

Here is the call graph for this function:

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.

Note
To remove json_object from root, mcl_json_util_destroy must be called for root json object.
Parameters
[out]json_objectJson object which exists in root.

Definition at line 836 of file json_util.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and json_util_finish_object().

Here is the call graph for this function:

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.

Parameters
[in]arrayArray json object.
[in]indexIndex of the item to get from array.
[out]itemResult json object item.New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space using MCL_FREE().
Returns

Definition at line 126 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_get_array_item().

Here is the call graph for this function:

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.

Parameters
[in]arrayArray json object.
[out]sizeSize of array.
Returns

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.

Here is the call graph for this function:

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.

Parameters
[in]jsonRoot object of bool_value.
[in]bool_valueBoolean value of json.
Returns

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.

Here is the call graph for this function:

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.

Parameters
[in]jsonRoot object of double_value.
[in]double_valueValue of json.
Returns

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.

Here is the call graph for this function:

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.

Parameters
[in]jsonRoot object of number_value.
[in]number_valueValue of json.
Returns

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.

Here is the call graph for this function:

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.

Parameters
[in]json_parentRoot json object of json_child.
[in]child_nameName of the json_child object.
[out]json_childThe 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().
Returns

Definition at line 549 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_get_object_item().

Here is the call graph for this function:

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.

Parameters
[in]json_itemRoot object of string_value.
[in]string_valueString value of json_item. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space.
Returns

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.

Here is the call graph for this function:

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.

Parameters
[in]rootJson object which is going to be checked whether it has child or not.
[out]resultThis bool value is going to be made true, if @ root has child. Otherwise it is false.
Returns

Definition at line 587 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, json_util_has_child(), and MCL_OK.

Here is the call graph for this function:

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.

Parameters
[in]json_typeType of the json.
[out]rootRoot json.
Returns

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().

Here is the call graph for this function:

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.

Parameters
[in]json_stringString 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]rootjson_string is going to be parsed to this root object.
Returns

Definition at line 748 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_parse().

Here is the call graph for this function:

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.

Parameters
[in]rootRoot json object.
[in]array_nameName of the array which is going to be created in root.
[out]json_arrayJson array which is going to be created in root.
Returns

Definition at line 84 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_start_array().

Here is the call graph for this function:

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.

Parameters
[in]rootRoot json object.
[in]object_nameName of the object which is going to be created in root.
[out]json_objectJson object which is going to be created in root.
Returns

Definition at line 182 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_start_object().

Here is the call graph for this function:

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.

Parameters
[in]rootRoot json object.
[out]json_stringThe string of root in json format. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space.
Returns

Definition at line 722 of file json_util.c.

References ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, and json_util_to_string().

Here is the call graph for this function:

Variable Documentation

cJSON_Hooks cjson_hooks
static

Definition at line 26 of file json_util.c.

Referenced by json_util_initialize_json_library().