json_util.h
Go to the documentation of this file.
1 /*!**********************************************************************
2 *
3 * @copyright Copyright (C) 2017 Siemens Aktiengesellschaft.\n
4 * All rights reserved.
5 *
6 *************************************************************************
7 *
8 * @file json_util.h
9 * @date Feb 22, 2017
10 * @brief Json util module header file.
11 *
12 * This module is used for json handling like json parsing and json generating.
13 *
14 ************************************************************************/
15 
16 #ifndef JSON_UTIL_H_
17 #define JSON_UTIL_H_
18 
19 #include "mcl/mcl_common.h"
20 #include "string_type.h"
21 
22 typedef struct cJSON cJSON;
23 
27 typedef struct mcl_json_t
28 {
30 } json_t;
31 
32 typedef enum E_JSON_TYPE
33 {
37 } E_JSON_TYPE;
38 
46 
59 
73 E_MCL_ERROR_CODE json_util_start_array(json_t *root, const char *array_name, json_t **json_array);
74 
87 E_MCL_ERROR_CODE json_util_get_array_item(json_t *array, int index, json_t **item);
88 
100 void json_util_get_array_size(json_t *array, mcl_size_t *size);
101 
115 E_MCL_ERROR_CODE json_util_start_object(json_t *root, const char *object_name, json_t **json_object);
116 
133 E_MCL_ERROR_CODE json_util_add_string(json_t *root, const char *object_name, const char *object_value);
134 
150 E_MCL_ERROR_CODE json_util_add_uint(json_t *root, const char *object_name, const mcl_size_t number);
151 
166 E_MCL_ERROR_CODE json_util_add_float(json_t *root, const char *object_name, const float number);
167 
181 E_MCL_ERROR_CODE json_util_add_double(json_t *root, const char *object_name, const double number);
182 
196 E_MCL_ERROR_CODE json_util_add_bool(json_t *root, const char *object_name, const mcl_bool_t bool_value);
197 
210 E_MCL_ERROR_CODE json_util_add_null(json_t *root, const char *object_name);
211 
225 E_MCL_ERROR_CODE json_util_add_object(json_t *root, const char *object_name, json_t *object);
226 
233 void json_util_add_item_to_array(json_t *root, json_t *object);
234 
248 E_MCL_ERROR_CODE json_util_get_object_item(json_t *json_parent, const char *child_name, json_t **json_child);
249 
261 
268 void json_util_get_number_value(json_t *json, mcl_int32_t *number_value);
269 
276 void json_util_get_double_value(json_t *json, double *double_value);
277 
284 void json_util_get_bool_value(json_t *json, mcl_bool_t *bool_value);
285 
297 E_MCL_ERROR_CODE json_util_get_string(json_t *json_item, string_t **string_value);
298 
310 E_MCL_ERROR_CODE json_util_to_string(json_t *root, char **json_string);
311 
324 E_MCL_ERROR_CODE json_util_parse(const char *json_string, json_t **root);
325 
340 E_MCL_ERROR_CODE json_util_parse_with_size(const char *json_string, mcl_size_t size, json_t **root);
341 
354 E_MCL_ERROR_CODE json_util_duplicate(const json_t *source_json, mcl_bool_t with_children, json_t **duplicated_json);
355 
363 void json_util_finish_array(json_t **json_array);
364 
372 void json_util_finish_object(json_t **json_object);
373 
381 void json_util_destroy(json_t **root);
382 
383 #endif //JSON_UTIL_H_
struct mcl_json_t mcl_json_t
This struct is used for json handling.
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.
Definition: json_util.c:237
void json_util_get_double_value(json_t *json, double *double_value)
This function gets the double value of a given json object.
Definition: json_util.c:651
void json_util_add_item_to_array(json_t *root, json_t *object)
This function adds object to root array.
Definition: json_util.c:540
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.
Definition: json_util.c:777
cJSON * root_handle
Root cJson object.
Definition: json_util.h:29
void json_util_destroy(json_t **root)
This function destroys root.
Definition: json_util.c:863
Common module interface header file.
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.
Definition: json_util.c:329
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.
Definition: json_util.c:454
void json_util_initialize_json_library()
This function initializes json library.
Definition: json_util.c:28
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.
Definition: json_util.c:141
E_MCL_ERROR_CODE
MCL Error code definitions. Every function returning an error code uses this enum values...
Definition: mcl_common.h:137
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.
Definition: json_util.c:629
Json array.
Definition: json_util.h:34
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.
Definition: json_util.c:198
Json null.
Definition: json_util.h:36
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.
Definition: json_util.c:805
void json_util_get_array_size(json_t *array, mcl_size_t *size)
This function returns the size of array.
Definition: json_util.c:173
struct cJSON cJSON
Definition: json_util.h:22
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.
Definition: json_util.c:100
E_MCL_ERROR_CODE json_util_add_object(json_t *root, const char *object_name, json_t *object)
This function adds object to root.
Definition: json_util.c:504
size_t mcl_size_t
Definition: mcl_common.h:38
mcl_uint8_t mcl_bool_t
Definition: mcl_common.h:47
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...
Definition: json_util.c:827
E_MCL_ERROR_CODE json_util_to_string(json_t *root, char **json_string)
This function gives the string of root in json format.
Definition: json_util.c:737
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...
Definition: json_util.c:845
Json object.
Definition: json_util.h:35
String type module header file.
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.
Definition: json_util.c:358
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.
Definition: json_util.c:285
E_MCL_ERROR_CODE json_util_initialize(E_JSON_TYPE json_type, json_t **root)
This function initializes the given root json.
Definition: json_util.c:53
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 give...
Definition: json_util.c:565
int32_t mcl_int32_t
Definition: mcl_common.h:41
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.
Definition: json_util.c:763
This struct is used for json handling.
Definition: json_util.h:27
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.
Definition: json_util.c:406
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.
Definition: json_util.c:673
mcl_bool_t json_util_has_child(json_t *root)
This function checks whether root object has child object or not.
Definition: json_util.c:600
E_JSON_TYPE
Definition: json_util.h:32
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.
Definition: json_util.c:711