coreJSON v3.3.1
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
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
50#define JSON_LIBRARY_VERSION "v3.3.1"
57#ifndef coreJSON_ASSERT
58 #define coreJSON_ASSERT( expr ) assert( expr )
59#endif
60
61
66typedef enum
67{
76
110/* @[declare_json_validate] */
111JSONStatus_t JSON_Validate( const char * buf,
112 size_t max );
113/* @[declare_json_validate] */
114
191/* @[declare_json_search] */
192#define JSON_Search( buf, max, query, queryLength, outValue, outValueLength ) \
193 JSON_SearchT( buf, max, query, queryLength, outValue, outValueLength, NULL )
194/* @[declare_json_search] */
195
200#define MAX_INDEX_VALUE ( 0x7FFFFFF7 ) /* 2^31 - 9 */
201
206typedef enum
207{
215 JSONArray
217
231/* @[declare_json_searcht] */
232JSONStatus_t JSON_SearchT( char * buf,
233 size_t max,
234 const char * query,
235 size_t queryLength,
236 char ** outValue,
237 size_t * outValueLength,
238 JSONTypes_t * outType );
239/* @[declare_json_searcht] */
240
254/* @[declare_json_searchconst] */
255JSONStatus_t JSON_SearchConst( const char * buf,
256 size_t max,
257 const char * query,
258 size_t queryLength,
259 const char ** outValue,
260 size_t * outValueLength,
261 JSONTypes_t * outType );
262/* @[declare_json_searchconst] */
263
268typedef struct
269{
270 const char * key;
271 size_t keyLength;
272 const char * value;
273 size_t valueLength;
275} JSONPair_t;
276
345/* @[declare_json_iterate] */
346JSONStatus_t JSON_Iterate( const char * buf,
347 size_t max,
348 size_t * start,
349 size_t * next,
350 JSONPair_t * outPair );
351/* @[declare_json_iterate] */
352
353/* *INDENT-OFF* */
354#ifdef __cplusplus
355 }
356#endif
357/* *INDENT-ON* */
358
359#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:1699
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:1749
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:1838
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:1196
JSONStatus_t
Return codes from coreJSON library functions.
Definition: core_json.h:67
JSONTypes_t
Value types from the JSON standard.
Definition: core_json.h:207
@ JSONNotFound
Query key could not be found in the JSON document.
Definition: core_json.h:72
@ JSONIllegalDocument
JSON document is invalid or malformed.
Definition: core_json.h:70
@ JSONSuccess
JSON document is valid and complete.
Definition: core_json.h:69
@ JSONBadParameter
Query key is empty, or any subpart is empty, or max is 0.
Definition: core_json.h:74
@ JSONMaxDepthExceeded
JSON document has nesting that exceeds JSON_MAX_DEPTH.
Definition: core_json.h:71
@ JSONNullParameter
Pointer parameter passed to a function is NULL.
Definition: core_json.h:73
@ JSONPartial
JSON document is valid so far but incomplete.
Definition: core_json.h:68
@ JSONObject
A collection of zero or more key-value pairs.
Definition: core_json.h:214
@ JSONNull
The literal value null.
Definition: core_json.h:213
@ JSONNumber
A rational number.
Definition: core_json.h:210
@ JSONTrue
The literal value true.
Definition: core_json.h:211
@ JSONString
A quote delimited sequence of Unicode characters.
Definition: core_json.h:209
@ JSONArray
A collection of zero or more values.
Definition: core_json.h:215
@ JSONFalse
The literal value false.
Definition: core_json.h:212
@ JSONInvalid
Not a valid JSON type.
Definition: core_json.h:208
Structure to represent a key-value pair.
Definition: core_json.h:269
const char * value
Pointer to the code point sequence for value.
Definition: core_json.h:272
size_t keyLength
Length of the code point sequence for key.
Definition: core_json.h:271
JSONTypes_t jsonType
JSON-specific type of the value.
Definition: core_json.h:274
size_t valueLength
Length of the code point sequence for value.
Definition: core_json.h:273
const char * key
Pointer to the code point sequence for key.
Definition: core_json.h:270