TI Utilities API  1.00.00.05
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  */
60 #ifndef ti_utils_json_Json__include
61 #define ti_utils_json_Json__include
62 
65 
66 /*
67  * ======== json.h ========
68  * @brief Contains JSON library APIs
69  */
70 
71 /*
72  * ==========================json scenario examples=========================
73  *
74  * Create json from | Parse the json and get | Parse the json, change
75  * scratch and build it | its value | its value and build it
76  * +--------------------+ | +--------------------+ | +--------------------+
77  * |Json_createTemplate | | |Json_createTemplate | | |Json_createTemplate |
78  * +--------------------+ | +--------------------+ | +--------------------+
79  * | | | | |
80  * v | v | v
81  * +--------------------+ | +--------------------+ | +--------------------+
82  * |Json_createObject | | |Json_createObject | | |Json_createObject |
83  * +--------------------+ | +--------------------+ | +--------------------+
84  * | | | | |
85  * v | v | v
86  * +--------------------+ | +--------------------+ | +--------------------+
87  * |Json_setValue | | |Json_parse | | |Json_parse |
88  * +--------------------+ | +--------------------+ | +--------------------+
89  * | | | | |
90  * v | v | v
91  * +--------------------+ | +--------------------+ | +--------------------+
92  * |Json_build | | |Json_getValue | | |Json_getValue |
93  * +--------------------+ | +--------------------+ | +--------------------+
94  * | | | | |
95  * v | v | v
96  * +--------------------+ | +--------------------+ | +--------------------+
97  * |Json_destroyObject | | |Json_destroyObject | | |Json_setValue |
98  * +--------------------+ | +--------------------+ | +--------------------+
99  * | | | | |
100  * v | v | v
101  * +--------------------+ | +--------------------+ | +--------------------+
102  * |Json_destroyTemplate| | |Json_destroyTemplate| | |Json_build |
103  * +--------------------+ | +--------------------+ | +--------------------+
104  * | | |
105  * | | v
106  * | | +--------------------+
107  * | | |Json_destroyObject |
108  * | | +--------------------+
109  * | | |
110  * | | v
111  * | | +--------------------+
112  * | | |Json_destroyTemplate|
113  * | | +--------------------+
114  *
115  * =========================================================================
116  */
117 
118 #include <stdlib.h>
119 #include <string.h>
120 #include "json_engine.h"
121 
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
125 
126 typedef size_t Json_Handle;
127 
128 #define JSON_DEFAULT_SIZE (1024u)
129 
159 int16_t Json_createTemplate(Json_Handle *templateHandle,
160  const char *templateString, uint16_t templateStringLen);
161 
162 
186 int16_t Json_destroyTemplate(Json_Handle templateHandle);
187 
214 int16_t Json_createObject(Json_Handle *objHandle, Json_Handle templateHandle,
215  uint16_t maxObjectSize);
216 
217 
235 int16_t Json_destroyObject(Json_Handle objHandle);
236 
259 int16_t Json_parse(Json_Handle objHandle, char *jsonText, uint16_t jsonTextLen);
260 
261 
290 int16_t Json_getArrayMembersCount(Json_Handle objHandle, const char *pKey);
291 
292 
330 int16_t Json_getValue(Json_Handle objHandle, const char *pKey, void *pValue,
331  uint16_t *maxValueSize);
332 
333 
365 int16_t Json_setValue(Json_Handle objHandle, const char *pKey, void *pValue,
366  uint16_t valueSize);
367 
368 
396 int16_t Json_build(Json_Handle objHandle, char *pJsonText, uint16_t *maxTxtLen);
397 
399 #ifdef __cplusplus
400 }
401 #endif
402 
403 #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:126
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-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale