coreJSON v3.3.0
Parser library for the ECMA-404 JSON standard
 
Loading...
Searching...
No Matches
core_json.h
Go to the documentation of this file.
1/*
2 * coreJSON v3.3.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 <assert.h>
34#include <stdbool.h>
35#include <stddef.h>
36
37/* *INDENT-OFF* */
38#ifdef __cplusplus
39 extern "C" {
40#endif
41/* *INDENT-ON* */
42
47#ifndef coreJSON_ASSERT
48 #define coreJSON_ASSERT( expr ) assert( expr )
49#endif
50
51
56typedef enum
57{
66
100/* @[declare_json_validate] */
101JSONStatus_t JSON_Validate( const char * buf,
102 size_t max );
103/* @[declare_json_validate] */
104
181/* @[declare_json_search] */
182#define JSON_Search( buf, max, query, queryLength, outValue, outValueLength ) \
183 JSON_SearchT( buf, max, query, queryLength, outValue, outValueLength, NULL )
184/* @[declare_json_search] */
185
190#define MAX_INDEX_VALUE ( 0x7FFFFFF7 ) /* 2^31 - 9 */
191
196typedef enum
197{
205 JSONArray
207
221/* @[declare_json_searcht] */
222JSONStatus_t JSON_SearchT( char * buf,
223 size_t max,
224 const char * query,
225 size_t queryLength,
226 char ** outValue,
227 size_t * outValueLength,
228 JSONTypes_t * outType );
229/* @[declare_json_searcht] */
230
244/* @[declare_json_searchconst] */
245JSONStatus_t JSON_SearchConst( const char * buf,
246 size_t max,
247 const char * query,
248 size_t queryLength,
249 const char ** outValue,
250 size_t * outValueLength,
251 JSONTypes_t * outType );
252/* @[declare_json_searchconst] */
253
258typedef struct
259{
260 const char * key;
261 size_t keyLength;
262 const char * value;
263 size_t valueLength;
265} JSONPair_t;
266
335/* @[declare_json_iterate] */
336JSONStatus_t JSON_Iterate( const char * buf,
337 size_t max,
338 size_t * start,
339 size_t * next,
340 JSONPair_t * outPair );
341/* @[declare_json_iterate] */
342
343/* *INDENT-OFF* */
344#ifdef __cplusplus
345 }
346#endif
347/* *INDENT-ON* */
348
349#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:1663
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:1713
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:1802
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:1160
JSONStatus_t
Return codes from coreJSON library functions.
Definition: core_json.h:57
JSONTypes_t
Value types from the JSON standard.
Definition: core_json.h:197
@ JSONNotFound
Query key could not be found in the JSON document.
Definition: core_json.h:62
@ JSONIllegalDocument
JSON document is invalid or malformed.
Definition: core_json.h:60
@ JSONSuccess
JSON document is valid and complete.
Definition: core_json.h:59
@ JSONBadParameter
Query key is empty, or any subpart is empty, or max is 0.
Definition: core_json.h:64
@ JSONMaxDepthExceeded
JSON document has nesting that exceeds JSON_MAX_DEPTH.
Definition: core_json.h:61
@ JSONNullParameter
Pointer parameter passed to a function is NULL.
Definition: core_json.h:63
@ JSONPartial
JSON document is valid so far but incomplete.
Definition: core_json.h:58
@ JSONObject
A collection of zero or more key-value pairs.
Definition: core_json.h:204
@ JSONNull
The literal value null.
Definition: core_json.h:203
@ JSONNumber
A rational number.
Definition: core_json.h:200
@ JSONTrue
The literal value true.
Definition: core_json.h:201
@ JSONString
A quote delimited sequence of Unicode characters.
Definition: core_json.h:199
@ JSONArray
A collection of zero or more values.
Definition: core_json.h:205
@ JSONFalse
The literal value false.
Definition: core_json.h:202
@ JSONInvalid
Not a valid JSON type.
Definition: core_json.h:198
Structure to represent a key-value pair.
Definition: core_json.h:259
const char * value
Pointer to the code point sequence for value.
Definition: core_json.h:262
size_t keyLength
Length of the code point sequence for key.
Definition: core_json.h:261
JSONTypes_t jsonType
JSON-specific type of the value.
Definition: core_json.h:264
size_t valueLength
Length of the code point sequence for value.
Definition: core_json.h:263
const char * key
Pointer to the code point sequence for key.
Definition: core_json.h:260