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