Network Services API  2.30.00.10
json.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
56 #ifndef ti_utils_json_Json__include
57 #define ti_utils_json_Json__include
58 
61 
62 /*
63  * ======== json.h ========
64  * @brief Contains JSON library APIs
65  */
66 
67 /*
68  * ==========================json scenario examples=========================
69  *
70  * Create json from | Parse the json and get | Parse the json, change
71  * scratch and build it | its value | its value and build it
72  * +--------------------+ | +--------------------+ | +--------------------+
73  * |Json_createTemplate | | |Json_createTemplate | | |Json_createTemplate |
74  * +--------------------+ | +--------------------+ | +--------------------+
75  * | | | | |
76  * v | v | v
77  * +--------------------+ | +--------------------+ | +--------------------+
78  * |Json_createObject | | |Json_createObject | | |Json_createObject |
79  * +--------------------+ | +--------------------+ | +--------------------+
80  * | | | | |
81  * v | v | v
82  * +--------------------+ | +--------------------+ | +--------------------+
83  * |Json_setValue | | |Json_parse | | |Json_parse |
84  * +--------------------+ | +--------------------+ | +--------------------+
85  * | | | | |
86  * v | v | v
87  * +--------------------+ | +--------------------+ | +--------------------+
88  * |Json_build | | |Json_getValue | | |Json_getValue |
89  * +--------------------+ | +--------------------+ | +--------------------+
90  * | | | | |
91  * v | v | v
92  * +--------------------+ | +--------------------+ | +--------------------+
93  * |Json_destroyObject | | |Json_destroyObject | | |Json_setValue |
94  * +--------------------+ | +--------------------+ | +--------------------+
95  * | | | | |
96  * v | v | v
97  * +--------------------+ | +--------------------+ | +--------------------+
98  * |Json_destroyTemplate| | |Json_destroyTemplate| | |Json_build |
99  * +--------------------+ | +--------------------+ | +--------------------+
100  * | | |
101  * | | v
102  * | | +--------------------+
103  * | | |Json_destroyObject |
104  * | | +--------------------+
105  * | | |
106  * | | v
107  * | | +--------------------+
108  * | | |Json_destroyTemplate|
109  * | | +--------------------+
110  *
111  * =========================================================================
112  */
113 
114 #include <stdlib.h>
115 #include <string.h>
116 #include "json_engine.h"
117 
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121 
122 typedef size_t Json_Handle;
123 
124 #define JSON_DEFAULT_SIZE (1024u)
125 
155 int16_t Json_createTemplate(Json_Handle *templateHandle,
156  const char *templateString, uint16_t templateStringLen);
157 
158 
182 int16_t Json_destroyTemplate(Json_Handle templateHandle);
183 
210 int16_t Json_createObject(Json_Handle *objHandle, Json_Handle templateHandle,
211  uint16_t maxObjectSize);
212 
213 
231 int16_t Json_destroyObject(Json_Handle objHandle);
232 
255 int16_t Json_parse(Json_Handle objHandle, char *jsonText, uint16_t jsonTextLen);
256 
257 
286 int16_t Json_getArrayMembersCount(Json_Handle objHandle, const char *pKey);
287 
288 
326 int16_t Json_getValue(Json_Handle objHandle, const char *pKey, void *pValue,
327  uint16_t *maxValueSize);
328 
329 
361 int16_t Json_setValue(Json_Handle objHandle, const char *pKey, void *pValue,
362  uint16_t valueSize);
363 
364 
392 int16_t Json_build(Json_Handle objHandle, char *pJsonText, uint16_t *maxTxtLen);
393 
395 #ifdef __cplusplus
396 }
397 #endif
398 
399 #endif
int16_t Json_setValue(Json_Handle objHandle, const char *pKey, void *pValue, uint16_t valueSize)
Sets the value for the provided key.
int16_t Json_parse(Json_Handle objHandle, char *jsonText, uint16_t jsonTextLen)
This function converts the json text into internal representation.
int16_t Json_getArrayMembersCount(Json_Handle objHandle, const char *pKey)
Retrieve the number of array elements in the provided key.
int16_t Json_getValue(Json_Handle objHandle, const char *pKey, void *pValue, uint16_t *maxValueSize)
This function retrieves value from json.
size_t Json_Handle
Definition: json.h:122
int16_t Json_build(Json_Handle objHandle, char *pJsonText, uint16_t *maxTxtLen)
This function builds the internal json into a text json.
int16_t Json_createTemplate(Json_Handle *templateHandle, const char *templateString, uint16_t templateStringLen)
This function creates internal template from the template text.
int16_t Json_destroyObject(Json_Handle objHandle)
Free the internal json memory.
int16_t Json_createObject(Json_Handle *objHandle, Json_Handle templateHandle, uint16_t maxObjectSize)
This function creates an empty Json object.
int16_t Json_destroyTemplate(Json_Handle templateHandle)
This function frees the internal template memory.
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale