ucx
UAP Common Extensions
Loading...
Searching...
No Matches
json.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
36#ifndef UCX_JSON_H
37#define UCX_JSON_H
38
39#include "common.h"
40#include "allocator.h"
41#include "string.h"
42#include "buffer.h"
43#include "array_list.h"
44
45#include <string.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51
109
143
161
170
174typedef struct cx_json_s CxJson;
175
180
185
201typedef int64_t CxJsonInteger;
205typedef double CxJsonNumber;
210
215
225
239
253
300
323
378
427
432
466
471
478cx_attr_export
480
488cx_attr_export
490
510cx_attr_nonnull_arg(1, 2, 3)
511cx_attr_export
513 void* target,
514 const CxJsonValue* value,
515 cx_write_func wfunc,
516 const CxJsonWriter* settings
517);
518
527cx_attr_export
528void cxJsonInit(CxJson *json, const CxAllocator *allocator);
529
537cx_attr_export
539
549static inline void cxJsonReset(CxJson *json) {
550 const CxAllocator *allocator = json->allocator;
551 cxJsonDestroy(json);
552 cxJsonInit(json, allocator);
553}
554
575cx_attr_export
576int cxJsonFilln(CxJson *json, const char *buf, size_t len);
577
578#ifdef __cplusplus
579} // extern "C"
580
582static inline int cxJsonFill(
583 CxJson *json,
584 cxstring str
585) {
586 return cxJsonFilln(json, str.ptr, str.length);
587}
588
590static inline int cxJsonFill(
591 CxJson *json,
592 cxmutstr str
593) {
594 return cxJsonFilln(json, str.ptr, str.length);
595}
596
599static inline int cxJsonFill(
600 CxJson *json,
601 const char *str
602) {
603 return cxJsonFilln(json, str, strlen(str));
604}
605
606extern "C" {
607#else // __cplusplus
625#define cxJsonFill(json, str) _Generic((str), \
626 cxstring: cx_json_fill_cxstr, \
627 cxmutstr: cx_json_fill_mutstr, \
628 char*: cx_json_fill_str, \
629 const char*: cx_json_fill_str) \
630 (json, str)
631
636static inline int cx_json_fill_cxstr(
637 CxJson *json,
638 cxstring str
639) {
640 return cxJsonFilln(json, str.ptr, str.length);
641}
642
647static inline int cx_json_fill_mutstr(
648 CxJson *json,
649 cxmutstr str
650) {
651 return cxJsonFilln(json, str.ptr, str.length);
652}
653
659static inline int cx_json_fill_str(
660 CxJson *json,
661 const char *str
662) {
663 return cxJsonFilln(json, str, strlen(str));
664}
665#endif
666
676cx_attr_export
678
688cx_attr_export
690
701cx_attr_export
702CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num);
703
714cx_attr_export
715CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num);
716
730cx_attr_export
731CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char *str);
732
744cx_attr_export
746
757cx_attr_export
759
771cx_attr_export
772int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count);
773
785cx_attr_export
786int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count);
787
802cx_attr_export
803int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count);
804
819cx_attr_export
820int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count);
821
833cx_attr_export
834int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t count);
835
850cx_attr_export
851int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count);
852
868cx_attr_export
870
881cx_attr_export
883
894cx_attr_export
896
908cx_attr_export
910
922cx_attr_export
924
939cx_attr_export
941
955cx_attr_export
957
969cx_attr_export
971
983cx_attr_export
985
1010cx_attr_export
1012
1021static inline bool cxJsonIsObject(const CxJsonValue *value) {
1022 return value->type == CX_JSON_OBJECT;
1023}
1024
1033static inline bool cxJsonIsArray(const CxJsonValue *value) {
1034 return value->type == CX_JSON_ARRAY;
1035}
1036
1045static inline bool cxJsonIsString(const CxJsonValue *value) {
1046 return value->type == CX_JSON_STRING;
1047}
1048
1061static inline bool cxJsonIsNumber(const CxJsonValue *value) {
1062 return value->type == CX_JSON_NUMBER || value->type == CX_JSON_INTEGER;
1063}
1064
1074static inline bool cxJsonIsInteger(const CxJsonValue *value) {
1075 return value->type == CX_JSON_INTEGER;
1076}
1077
1091static inline bool cxJsonIsLiteral(const CxJsonValue *value) {
1092 return value->type == CX_JSON_LITERAL;
1093}
1094
1105static inline bool cxJsonIsBool(const CxJsonValue *value) {
1106 return cxJsonIsLiteral(value) && value->value.literal != CX_JSON_NULL;
1107}
1108
1122static inline bool cxJsonIsTrue(const CxJsonValue *value) {
1123 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_TRUE;
1124}
1125
1139static inline bool cxJsonIsFalse(const CxJsonValue *value) {
1140 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_FALSE;
1141}
1142
1152static inline bool cxJsonIsNull(const CxJsonValue *value) {
1153 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_NULL;
1154}
1155
1167static inline char *cxJsonAsString(const CxJsonValue *value) {
1168 return value->value.string.ptr;
1169}
1170
1181static inline cxstring cxJsonAsCxString(const CxJsonValue *value) {
1182 return cx_strcast(value->value.string);
1183}
1184
1195static inline cxmutstr cxJsonAsCxMutStr(const CxJsonValue *value) {
1196 return value->value.string;
1197}
1198
1209static inline double cxJsonAsDouble(const CxJsonValue *value) {
1210 if (value->type == CX_JSON_INTEGER) {
1211 return (double) value->value.integer;
1212 } else {
1213 return value->value.number;
1214 }
1215}
1216
1230static inline int64_t cxJsonAsInteger(const CxJsonValue *value) {
1231 if (value->type == CX_JSON_INTEGER) {
1232 return value->value.integer;
1233 } else {
1234 return (int64_t) value->value.number;
1235 }
1236}
1237
1249static inline bool cxJsonAsBool(const CxJsonValue *value) {
1250 return value->value.literal == CX_JSON_TRUE;
1251}
1252
1263static inline size_t cxJsonArrSize(const CxJsonValue *value) {
1264 return value->value.array.array_size;
1265}
1266
1283cx_attr_export
1284CxJsonValue *cxJsonArrGet(const CxJsonValue *value, size_t index);
1285
1299cx_attr_export
1301
1316cx_attr_export
1318
1324cx_attr_export
1326
1327#ifdef __cplusplus
1328} // extern "C"
1329
1330static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) {
1331 return cx_json_obj_get_cxstr(value, name);
1332}
1333
1334static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxmutstr name) {
1335 return cx_json_obj_get_cxstr(value, cx_strcast(name));
1336}
1337
1338static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) {
1339 return cx_json_obj_get_cxstr(value, cx_str(name));
1340}
1341
1342extern "C" {
1343#else
1358#define cxJsonObjGet(value, name) _Generic((name), \
1359 cxstring: cx_json_obj_get_cxstr, \
1360 cxmutstr: cx_json_obj_get_mutstr, \
1361 char*: cx_json_obj_get_str, \
1362 const char*: cx_json_obj_get_str) \
1363 (value, name)
1364
1370static inline CxJsonValue *cx_json_obj_get_mutstr(const CxJsonValue *value, cxmutstr name) {
1371 return cx_json_obj_get_cxstr(value, cx_strcast(name));
1372}
1373
1380static inline CxJsonValue *cx_json_obj_get_str(const CxJsonValue *value, const char *name) {
1381 return cx_json_obj_get_cxstr(value, cx_str(name));
1382}
1383#endif
1384
1385#ifdef __cplusplus
1386}
1387#endif
1388
1389#endif /* UCX_JSON_H */
1390
Interface for custom allocators.
Array list implementation.
#define CX_ARRAY_DECLARE_SIZED(type, name, size_type)
Declares variables for an array that can be used with the convenience macros.
Definition array_list.h:79
#define CX_ARRAY_DECLARE(type, name)
Declares variables for an array that can be used with the convenience macros.
Definition array_list.h:108
Advanced buffer implementation.
Common definitions and feature checks.
#define cx_attr_returns_nonnull
The returned value is guaranteed to be non-NULL.
Definition common.h:146
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
size_t(* cx_write_func)(const void *, size_t, size_t, void *)
Function pointer compatible with fwrite-like functions.
Definition common.h:294
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_access_w(...)
Specifies that the function will only write through the given pointer.
Definition common.h:241
#define cx_attr_access_r(...)
Specifies that the function will only read through the given pointer.
Definition common.h:225
#define cx_attr_nonnull_arg(...)
The specified pointer arguments must be non-NULL.
Definition common.h:141
#define cx_attr_cstr_arg(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:206
enum cx_json_status CxJsonStatus
Typedef for the json status enum.
Definition json.h:431
int cxJsonFilln(CxJson *json, const char *buf, size_t len)
Fills the input buffer.
static bool cxJsonIsArray(const CxJsonValue *value)
Checks if the specified value is a JSON array.
Definition json.h:1033
static int cx_json_fill_cxstr(CxJson *json, cxstring str)
Fills the input buffer.
Definition json.h:636
int cxJsonObjPut(CxJsonValue *obj, cxstring name, CxJsonValue *child)
Adds or replaces a value within a JSON object.
double CxJsonNumber
Type alias for number that is not an integer.
Definition json.h:205
static cxstring cxJsonAsCxString(const CxJsonValue *value)
Obtains a UCX string from the given JSON value.
Definition json.h:1181
CxJsonWriter cxJsonWriterPretty(bool use_spaces)
Creates a default writer configuration for pretty output.
int cxJsonArrAddCxStrings(CxJsonValue *arr, const cxstring *str, size_t count)
Adds strings to a JSON array.
CxJsonValue * cxJsonCreateLiteral(const CxAllocator *allocator, CxJsonLiteral lit)
Creates a new JSON literal.
#define cxJsonFill(json, str)
Fills the input buffer.
Definition json.h:625
CxJsonValue * cxJsonObjPutObj(CxJsonValue *obj, cxstring name)
Creates a new JSON object and adds it to an existing object.
int cxJsonArrAddLiterals(CxJsonValue *arr, const CxJsonLiteral *lit, size_t count)
Adds literals to a JSON array.
static bool cxJsonIsFalse(const CxJsonValue *value)
Checks if the specified value is false.
Definition json.h:1139
static CxJsonValue * cx_json_obj_get_str(const CxJsonValue *value, const char *name)
Returns a value corresponding to a key in a JSON object.
Definition json.h:1380
CxJsonValue * cxJsonObjPutNumber(CxJsonValue *obj, cxstring name, double num)
Creates a new JSON number and adds it to an object.
CxJsonValue * cxJsonCreateObj(const CxAllocator *allocator)
Creates a new (empty) JSON object.
static int cx_json_fill_str(CxJson *json, const char *str)
Fills the input buffer.
Definition json.h:659
CxJsonValue * cxJsonObjPutArr(CxJsonValue *obj, cxstring name)
Creates a new JSON array and adds it to an object.
int cxJsonArrAddValues(CxJsonValue *arr, CxJsonValue *const *val, size_t count)
Add arbitrary values to a JSON array.
CxJsonStatus cxJsonNext(CxJson *json, CxJsonValue **value)
Tries to obtain the next JSON value.
static size_t cxJsonArrSize(const CxJsonValue *value)
Returns the size of a JSON array.
Definition json.h:1263
enum cx_json_literal CxJsonLiteral
Type alias for a JSON literal.
Definition json.h:209
CxJsonValue * cxJsonCreateArr(const CxAllocator *allocator)
Creates a new (empty) JSON array.
int cxJsonArrAddStrings(CxJsonValue *arr, const char *const *str, size_t count)
Adds strings to a JSON array.
CxJsonValue * cxJsonObjPutLiteral(CxJsonValue *obj, cxstring name, CxJsonLiteral lit)
Creates a new JSON literal and adds it to an object.
static void cxJsonReset(CxJson *json)
Destroys and re-initializes the json interface.
Definition json.h:549
CxJsonValue * cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name)
Returns a value corresponding to a key in a JSON object.
static int cx_json_fill_mutstr(CxJson *json, cxmutstr str)
Fills the input buffer.
Definition json.h:647
static double cxJsonAsDouble(const CxJsonValue *value)
Obtains a double-precision floating point value from the given JSON value.
Definition json.h:1209
static bool cxJsonIsBool(const CxJsonValue *value)
Checks if the specified value is a Boolean literal.
Definition json.h:1105
static bool cxJsonIsTrue(const CxJsonValue *value)
Checks if the specified value is true.
Definition json.h:1122
static char * cxJsonAsString(const CxJsonValue *value)
Obtains a C string from the given JSON value.
Definition json.h:1167
int cxJsonArrAddNumbers(CxJsonValue *arr, const double *num, size_t count)
Adds number values to a JSON array.
cx_json_token_type
The type of the parsed token.
Definition json.h:55
@ CX_JSON_TOKEN_ERROR
The presumed token contains syntactical errors.
Definition json.h:63
@ CX_JSON_TOKEN_END_OBJECT
An "end of object" '}' token.
Definition json.h:79
@ CX_JSON_NO_TOKEN
No complete token parsed, yet.
Definition json.h:59
@ CX_JSON_TOKEN_END_ARRAY
An "end of array" ']' token.
Definition json.h:75
@ CX_JSON_TOKEN_STRING
A string token.
Definition json.h:91
@ CX_JSON_TOKEN_BEGIN_ARRAY
A "begin of array" '[' token.
Definition json.h:67
@ CX_JSON_TOKEN_NUMBER
A number token that cannot be represented as integer.
Definition json.h:99
@ CX_JSON_TOKEN_SPACE
A white-space token.
Definition json.h:107
@ CX_JSON_TOKEN_LITERAL
A literal token.
Definition json.h:103
@ CX_JSON_TOKEN_NAME_SEPARATOR
A colon ':' token separating names and values.
Definition json.h:83
@ CX_JSON_TOKEN_VALUE_SEPARATOR
A comma ',' token separating object entries or array elements.
Definition json.h:87
@ CX_JSON_TOKEN_INTEGER
A number token that can be represented as integer.
Definition json.h:95
@ CX_JSON_TOKEN_BEGIN_OBJECT
A "begin of object" '{' token.
Definition json.h:71
CxJsonValue * cxJsonArrGet(const CxJsonValue *value, size_t index)
Returns an element from a JSON array.
CxJsonValue * cxJsonCreateNumber(const CxAllocator *allocator, double num)
Creates a new JSON number value.
CxJsonValue * cxJsonObjPutCxString(CxJsonValue *obj, cxstring name, cxstring str)
Creates a new JSON string and adds it to an object.
static bool cxJsonIsLiteral(const CxJsonValue *value)
Checks if the specified value is a JSON literal.
Definition json.h:1091
static bool cxJsonIsObject(const CxJsonValue *value)
Checks if the specified value is a JSON object.
Definition json.h:1021
void cxJsonInit(CxJson *json, const CxAllocator *allocator)
Initializes the json interface.
cx_json_value_type
The type of some JSON value.
Definition json.h:113
@ CX_JSON_LITERAL
A literal (true, false, null).
Definition json.h:141
@ CX_JSON_NUMBER
A number, not necessarily an integer.
Definition json.h:137
@ CX_JSON_NOTHING
Reserved.
Definition json.h:117
@ CX_JSON_ARRAY
A JSON array.
Definition json.h:125
@ CX_JSON_INTEGER
A number that contains an integer.
Definition json.h:133
@ CX_JSON_OBJECT
A JSON object.
Definition json.h:121
@ CX_JSON_STRING
A string.
Definition json.h:129
CxJsonWriter cxJsonWriterCompact(void)
Creates a default writer configuration for compact output.
int cxJsonArrAddIntegers(CxJsonValue *arr, const int64_t *num, size_t count)
Adds number values, of which all are integers, to a JSON array.
static CxJsonValue * cx_json_obj_get_mutstr(const CxJsonValue *value, cxmutstr name)
Returns a value corresponding to a key in a JSON object.
Definition json.h:1370
enum cx_json_token_type CxJsonTokenType
Type alias for the token type enum.
Definition json.h:165
static cxmutstr cxJsonAsCxMutStr(const CxJsonValue *value)
Obtains a mutable UCX string from the given JSON value.
Definition json.h:1195
static bool cxJsonIsString(const CxJsonValue *value)
Checks if the specified value is a string.
Definition json.h:1045
cx_json_status
Status codes for the json interface.
Definition json.h:382
@ CX_JSON_FORMAT_ERROR_NUMBER
A number value is incorrectly formatted.
Definition json.h:421
@ CX_JSON_NO_DATA
The input buffer does not contain more data.
Definition json.h:390
@ CX_JSON_BUFFER_ALLOC_FAILED
Allocating memory for the internal buffer failed.
Definition json.h:413
@ CX_JSON_OK
Not used as a status and never returned by any function.
Definition json.h:405
@ CX_JSON_INCOMPLETE_DATA
The input ends unexpectedly.
Definition json.h:396
@ CX_JSON_NO_ERROR
Everything is fine.
Definition json.h:386
@ CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN
The tokenizer found something unexpected.
Definition json.h:425
@ CX_JSON_NULL_DATA
The input buffer has never been filled.
Definition json.h:409
@ CX_JSON_VALUE_ALLOC_FAILED
Allocating memory for a json value failed.
Definition json.h:417
int64_t CxJsonInteger
Type alias for a number that can be represented as 64-bit signed integer.
Definition json.h:201
enum cx_json_value_type CxJsonValueType
Type alias for the value type enum.
Definition json.h:169
static bool cxJsonIsNull(const CxJsonValue *value)
Checks if the specified value is null.
Definition json.h:1152
static bool cxJsonAsBool(const CxJsonValue *value)
Obtains a Boolean value from the given JSON value.
Definition json.h:1249
static bool cxJsonIsNumber(const CxJsonValue *value)
Checks if the specified value is a JSON number.
Definition json.h:1061
CxJsonValue * cxJsonObjPutInteger(CxJsonValue *obj, cxstring name, int64_t num)
Creates a new JSON number, based on an integer, and adds it to an object.
CxJsonValue * cxJsonObjPutString(CxJsonValue *obj, cxstring name, const char *str)
Creates a new JSON string and adds it to an object.
int cxJsonWrite(void *target, const CxJsonValue *value, cx_write_func wfunc, const CxJsonWriter *settings)
Writes a JSON value to a buffer or stream.
CxJsonValue * cxJsonCreateInteger(const CxAllocator *allocator, int64_t num)
Creates a new JSON number value based on an integer.
cx_json_literal
JSON literal types.
Definition json.h:147
@ CX_JSON_TRUE
The true literal.
Definition json.h:155
@ CX_JSON_NULL
The null literal.
Definition json.h:151
@ CX_JSON_FALSE
The false literal.
Definition json.h:159
#define cxJsonObjGet(value, name)
Returns a value corresponding to a key in a JSON object.
Definition json.h:1358
void cxJsonDestroy(CxJson *json)
Destroys the json interface.
static bool cxJsonIsInteger(const CxJsonValue *value)
Checks if the specified value is an integer number.
Definition json.h:1074
void cxJsonValueFree(CxJsonValue *value)
Recursively deallocates the memory of a JSON value.
static int64_t cxJsonAsInteger(const CxJsonValue *value)
Obtains a 64-bit signed integer from the given JSON value.
Definition json.h:1230
CxIterator cxJsonArrIter(const CxJsonValue *value)
Returns an iterator over the JSON array elements.
CxIterator cxJsonObjIter(const CxJsonValue *value)
Returns an iterator over the JSON object members.
CxJsonValue * cxJsonCreateString(const CxAllocator *allocator, const char *str)
Creates a new JSON string.
CxJsonValue * cxJsonCreateCxString(const CxAllocator *allocator, cxstring str)
Creates a new JSON string.
Strings that know their length.
cxstring cx_str(const char *cstring)
Wraps a string that must be zero-terminated.
#define cx_strcast(str)
Casts a mutable string to an immutable string.
Definition string.h:295
Structure holding the data for an allocator.
Definition allocator.h:84
Structure for the UCX buffer data.
Definition buffer.h:157
Internal iterator struct - use CxIterator.
Definition iterator.h:91
JSON array structure.
Definition json.h:219
size_t array_size
Array size.
Definition json.h:223
CxJsonValue ** array
The array data.
Definition json.h:223
Structure for a key/value entry in a JSON object.
Definition json.h:243
CxJsonValue * value
The value.
Definition json.h:251
cxmutstr name
The key (or name in JSON terminology) of the value.
Definition json.h:247
JSON object structure.
Definition json.h:229
CxJsonObjValue * values
The key/value entries.
Definition json.h:233
size_t * indices
The original indices to reconstruct the order in which the members were added.
Definition json.h:237
The JSON parser interface.
Definition json.h:327
int states_internal[8]
Internally reserved memory for the state stack.
Definition json.h:371
CxJsonObjValue uncompleted_member
A pointer to an intermediate state of a currently parsed object member.
Definition json.h:356
int * states
State stack.
Definition json.h:361
const CxAllocator * allocator
The allocator used for produced JSON values.
Definition json.h:331
CxBuffer buffer
The input buffer.
Definition json.h:335
CxJsonValue ** vbuf
Value buffer stack.
Definition json.h:366
CxJsonValue * vbuf_internal[8]
Internally reserved memory for the value buffer stack.
Definition json.h:376
CxJsonToken uncompleted
Used internally.
Definition json.h:342
CxJsonValue * parsed
A pointer to an intermediate state of the currently parsed value.
Definition json.h:349
Internally used structure for a parsed token.
Definition json.h:306
cxmutstr content
The token text, if any.
Definition json.h:321
CxJsonTokenType tokentype
The token type.
Definition json.h:310
bool allocated
True, if the content must be passed to cx_strfree().
Definition json.h:314
Structure for a JSON value.
Definition json.h:257
const CxAllocator * allocator
The allocator with which the value was allocated.
Definition json.h:263
CxJsonArray array
The array data if type is CX_JSON_ARRAY.
Definition json.h:277
CxJsonLiteral literal
The literal type if type is CX_JSON_LITERAL.
Definition json.h:297
CxJsonNumber number
The number if type is CX_JSON_NUMBER.
Definition json.h:293
union cx_json_value_s::@3 value
The value data.
CxJsonString string
The string data if type is CX_JSON_STRING.
Definition json.h:285
CxJsonValueType type
The type of this value.
Definition json.h:269
CxJsonInteger integer
The integer if type is CX_JSON_INTEGER.
Definition json.h:289
CxJsonObject object
The object data if type is CX_JSON_OBJECT.
Definition json.h:281
The JSON writer settings.
Definition json.h:436
bool sort_members
Set false to output the members in the order in which they were added.
Definition json.h:444
bool indent_space
Set true to use spaces instead of tab characters.
Definition json.h:455
bool escape_slash
Set true to enable escaping of the slash character (solidus).
Definition json.h:464
uint8_t indent
If indent_space is true, this is the number of spaces per tab.
Definition json.h:460
uint8_t frac_max_digits
The maximum number of fractional digits in a number value.
Definition json.h:450
bool pretty
Set true to enable pretty output.
Definition json.h:440
The UCX string structure.
Definition string.h:51
char * ptr
A pointer to the string.
Definition string.h:56
size_t length
The length of the string.
Definition string.h:58
The UCX string structure for immutable (constant) strings.
Definition string.h:69
size_t length
The length of the string.
Definition string.h:76
const char * ptr
A pointer to the immutable string.
Definition string.h:74