coreJSON v3.0.1
Parser library for the ECMA-404 JSON standard
core_json.h
Go to the documentation of this file.
1/*
2 * coreJSON v3.0.1
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
38typedef enum
39{
48
82/* @[declare_json_validate] */
83JSONStatus_t JSON_Validate( const char * buf,
84 size_t max );
85/* @[declare_json_validate] */
86
163/* @[declare_json_search] */
164#define JSON_Search( buf, max, query, queryLength, outValue, outValueLength ) \
165 JSON_SearchT( buf, max, query, queryLength, outValue, outValueLength, NULL )
166/* @[declare_json_search] */
167
172#define MAX_INDEX_VALUE ( 0x7FFFFFF7 ) /* 2^31 - 9 */
173
178typedef enum
179{
187 JSONArray
189
203/* @[declare_json_searcht] */
204JSONStatus_t JSON_SearchT( char * buf,
205 size_t max,
206 const char * query,
207 size_t queryLength,
208 char ** outValue,
209 size_t * outValueLength,
210 JSONTypes_t * outType );
211/* @[declare_json_searcht] */
212
226/* @[declare_json_searchconst] */
227JSONStatus_t JSON_SearchConst( const char * buf,
228 size_t max,
229 const char * query,
230 size_t queryLength,
231 const char ** outValue,
232 size_t * outValueLength,
233 JSONTypes_t * outType );
234/* @[declare_json_searchconst] */
235
240typedef struct
241{
242 const char * key;
243 size_t keyLength;
244 const char * value;
245 size_t valueLength;
247} JSONPair_t;
248
317/* @[declare_json_iterate] */
318JSONStatus_t JSON_Iterate( const char * buf,
319 size_t max,
320 size_t * start,
321 size_t * next,
322 JSONPair_t * outPair );
323/* @[declare_json_iterate] */
324#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:1614
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:1664
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:1755
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:1118
JSONStatus_t
Return codes from coreJSON library functions.
Definition: core_json.h:39
JSONTypes_t
Value types from the JSON standard.
Definition: core_json.h:179
@ JSONNotFound
Query key could not be found in the JSON document.
Definition: core_json.h:44
@ JSONIllegalDocument
JSON document is invalid or malformed.
Definition: core_json.h:42
@ JSONSuccess
JSON document is valid and complete.
Definition: core_json.h:41
@ JSONBadParameter
Query key is empty, or any subpart is empty, or max is 0.
Definition: core_json.h:46
@ JSONMaxDepthExceeded
JSON document has nesting that exceeds JSON_MAX_DEPTH.
Definition: core_json.h:43
@ JSONNullParameter
Pointer parameter passed to a function is NULL.
Definition: core_json.h:45
@ JSONPartial
JSON document is valid so far but incomplete.
Definition: core_json.h:40
@ JSONObject
A collection of zero or more key-value pairs.
Definition: core_json.h:186
@ JSONNull
The literal value null.
Definition: core_json.h:185
@ JSONNumber
A rational number.
Definition: core_json.h:182
@ JSONTrue
The literal value true.
Definition: core_json.h:183
@ JSONString
A quote delimited sequence of Unicode characters.
Definition: core_json.h:181
@ JSONArray
A collection of zero or more values.
Definition: core_json.h:187
@ JSONFalse
The literal value false.
Definition: core_json.h:184
@ JSONInvalid
Not a valid JSON type.
Definition: core_json.h:180
Structure to represent a key-value pair.
Definition: core_json.h:241
const char * value
Pointer to the code point sequence for value.
Definition: core_json.h:244
size_t keyLength
Length of the code point sequence for key.
Definition: core_json.h:243
JSONTypes_t jsonType
JSON-specific type of the value.
Definition: core_json.h:246
size_t valueLength
Length of the code point sequence for value.
Definition: core_json.h:245
const char * key
Pointer to the code point sequence for key.
Definition: core_json.h:242