coreJSON  v3.0.2
Parser library for the ECMA-404 JSON standard
core_json.h
Go to the documentation of this file.
1 /*
2  * coreJSON v3.0.2
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
28 #ifndef CORE_JSON_H_
29 #define CORE_JSON_H_
30 
31 #include <stdbool.h>
32 #include <stddef.h>
33 
34 /* *INDENT-OFF* */
35 #ifdef __cplusplus
36  extern "C" {
37 #endif
38 /* *INDENT-ON* */
39 
44 typedef enum
45 {
54 
88 /* @[declare_json_validate] */
89 JSONStatus_t JSON_Validate( const char * buf,
90  size_t max );
91 /* @[declare_json_validate] */
92 
169 /* @[declare_json_search] */
170 #define JSON_Search( buf, max, query, queryLength, outValue, outValueLength ) \
171  JSON_SearchT( buf, max, query, queryLength, outValue, outValueLength, NULL )
172 /* @[declare_json_search] */
173 
178 #define MAX_INDEX_VALUE ( 0x7FFFFFF7 ) /* 2^31 - 9 */
179 
184 typedef enum
185 {
193  JSONArray
195 
209 /* @[declare_json_searcht] */
210 JSONStatus_t JSON_SearchT( char * buf,
211  size_t max,
212  const char * query,
213  size_t queryLength,
214  char ** outValue,
215  size_t * outValueLength,
216  JSONTypes_t * outType );
217 /* @[declare_json_searcht] */
218 
232 /* @[declare_json_searchconst] */
233 JSONStatus_t JSON_SearchConst( const char * buf,
234  size_t max,
235  const char * query,
236  size_t queryLength,
237  const char ** outValue,
238  size_t * outValueLength,
239  JSONTypes_t * outType );
240 /* @[declare_json_searchconst] */
241 
246 typedef struct
247 {
248  const char * key;
249  size_t keyLength;
250  const char * value;
251  size_t valueLength;
253 } JSONPair_t;
254 
323 /* @[declare_json_iterate] */
324 JSONStatus_t JSON_Iterate( const char * buf,
325  size_t max,
326  size_t * start,
327  size_t * next,
328  JSONPair_t * outPair );
329 /* @[declare_json_iterate] */
330 
331 /* *INDENT-OFF* */
332 #ifdef __cplusplus
333  }
334 #endif
335 /* *INDENT-ON* */
336 
337 #endif /* ifndef CORE_JSON_H_ */
JSONNumber
@ JSONNumber
A rational number.
Definition: core_json.h:188
JSONNotFound
@ JSONNotFound
Query key could not be found in the JSON document.
Definition: core_json.h:50
JSONPair_t::value
const char * value
Pointer to the code point sequence for value.
Definition: core_json.h:250
JSONSuccess
@ JSONSuccess
JSON document is valid and complete.
Definition: core_json.h:47
JSONTrue
@ JSONTrue
The literal value true.
Definition: core_json.h:189
JSON_SearchConst
JSONStatus_t JSON_SearchConst(const char *buf, size_t max, const char *query, size_t queryLength, const char **outValue, size_t *outValueLength, JSONTypes_t *outType)
Same as JSON_SearchT(), but with const qualified buf and outValue arguments.
Definition: core_json.c:1621
JSONPair_t::valueLength
size_t valueLength
Length of the code point sequence for value.
Definition: core_json.h:251
JSONPair_t
Structure to represent a key-value pair.
Definition: core_json.h:247
JSONNullParameter
@ JSONNullParameter
Pointer parameter passed to a function is NULL.
Definition: core_json.h:51
JSONPair_t::jsonType
JSONTypes_t jsonType
JSON-specific type of the value.
Definition: core_json.h:252
JSONPair_t::keyLength
size_t keyLength
Length of the code point sequence for key.
Definition: core_json.h:249
JSONTypes_t
JSONTypes_t
Value types from the JSON standard.
Definition: core_json.h:185
JSONFalse
@ JSONFalse
The literal value false.
Definition: core_json.h:190
JSON_Validate
JSONStatus_t JSON_Validate(const char *buf, size_t max)
Parse a buffer to determine if it contains a valid JSON document.
Definition: core_json.c:1123
JSONArray
@ JSONArray
A collection of zero or more values.
Definition: core_json.h:193
JSONString
@ JSONString
A quote delimited sequence of Unicode characters.
Definition: core_json.h:187
JSONInvalid
@ JSONInvalid
Not a valid JSON type.
Definition: core_json.h:186
JSONStatus_t
JSONStatus_t
Return codes from coreJSON library functions.
Definition: core_json.h:45
JSON_Iterate
JSONStatus_t JSON_Iterate(const char *buf, size_t max, size_t *start, size_t *next, JSONPair_t *outPair)
Output the next key-value pair or value from a collection.
Definition: core_json.c:1762
JSONIllegalDocument
@ JSONIllegalDocument
JSON document is invalid or malformed.
Definition: core_json.h:48
JSONBadParameter
@ JSONBadParameter
Query key is empty, or any subpart is empty, or max is 0.
Definition: core_json.h:52
JSONPair_t::key
const char * key
Pointer to the code point sequence for key.
Definition: core_json.h:248
JSONPartial
@ JSONPartial
JSON document is valid so far but incomplete.
Definition: core_json.h:46
JSONMaxDepthExceeded
@ JSONMaxDepthExceeded
JSON document has nesting that exceeds JSON_MAX_DEPTH.
Definition: core_json.h:49
JSONNull
@ JSONNull
The literal value null.
Definition: core_json.h:191
JSON_SearchT
JSONStatus_t JSON_SearchT(char *buf, size_t max, const char *query, size_t queryLength, char **outValue, size_t *outValueLength, JSONTypes_t *outType)
Same as JSON_Search(), but also outputs a type for the value found.
Definition: core_json.c:1671
JSONObject
@ JSONObject
A collection of zero or more key-value pairs.
Definition: core_json.h:192