coreJSON v3.1.0
Parser library for the ECMA-404 JSON standard
core_json.h
Go to the documentation of this file.
1/*
2 * coreJSON v3.1.0
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
44typedef enum
45{
54
88/* @[declare_json_validate] */
89JSONStatus_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
184typedef enum
185{
193 JSONArray
195
209/* @[declare_json_searcht] */
210JSONStatus_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] */
233JSONStatus_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
246typedef 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] */
324JSONStatus_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_ */
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
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
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
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
JSONStatus_t
Return codes from coreJSON library functions.
Definition: core_json.h:45
JSONTypes_t
Value types from the JSON standard.
Definition: core_json.h:185
@ JSONNotFound
Query key could not be found in the JSON document.
Definition: core_json.h:50
@ JSONIllegalDocument
JSON document is invalid or malformed.
Definition: core_json.h:48
@ JSONSuccess
JSON document is valid and complete.
Definition: core_json.h:47
@ JSONBadParameter
Query key is empty, or any subpart is empty, or max is 0.
Definition: core_json.h:52
@ JSONMaxDepthExceeded
JSON document has nesting that exceeds JSON_MAX_DEPTH.
Definition: core_json.h:49
@ JSONNullParameter
Pointer parameter passed to a function is NULL.
Definition: core_json.h:51
@ JSONPartial
JSON document is valid so far but incomplete.
Definition: core_json.h:46
@ JSONObject
A collection of zero or more key-value pairs.
Definition: core_json.h:192
@ JSONNull
The literal value null.
Definition: core_json.h:191
@ JSONNumber
A rational number.
Definition: core_json.h:188
@ JSONTrue
The literal value true.
Definition: core_json.h:189
@ JSONString
A quote delimited sequence of Unicode characters.
Definition: core_json.h:187
@ JSONArray
A collection of zero or more values.
Definition: core_json.h:193
@ JSONFalse
The literal value false.
Definition: core_json.h:190
@ JSONInvalid
Not a valid JSON type.
Definition: core_json.h:186
Structure to represent a key-value pair.
Definition: core_json.h:247
const char * value
Pointer to the code point sequence for value.
Definition: core_json.h:250
size_t keyLength
Length of the code point sequence for key.
Definition: core_json.h:249
JSONTypes_t jsonType
JSON-specific type of the value.
Definition: core_json.h:252
size_t valueLength
Length of the code point sequence for value.
Definition: core_json.h:251
const char * key
Pointer to the code point sequence for key.
Definition: core_json.h:248