FreeRDP
Loading...
Searching...
No Matches
json.c
1
20#include <math.h>
21#include <errno.h>
22
23#include <winpr/file.h>
24#include <winpr/json.h>
25#include <winpr/assert.h>
26
27#if defined(WITH_CJSON)
28#include <cjson/cJSON.h>
29#endif
30#if defined(WITH_JSONC)
31#include <json.h>
32#endif
33
34#if defined(WITH_CJSON)
35#if CJSON_VERSION_MAJOR == 1
36#if (CJSON_VERSION_MINOR < 7) || ((CJSON_VERSION_MINOR == 7) && (CJSON_VERSION_PATCH < 13))
37#define USE_CJSON_COMPAT
38#endif
39#endif
40#endif
41
42#if defined(WITH_JSONC)
43#if JSON_C_MAJOR_VERSION == 0
44#if JSON_C_MINOR_VERSION < 14
45static struct json_object* json_object_new_null(void)
46{
47 return NULL;
48}
49#endif
50#endif
51#endif
52
53#if defined(USE_CJSON_COMPAT)
54static double cJSON_GetNumberValue(const cJSON* prop)
55{
56#ifndef NAN
57#ifdef _WIN32
58#define NAN sqrt(-1.0)
59#define COMPAT_NAN_UNDEF
60#else
61#define NAN 0.0 / 0.0
62#define COMPAT_NAN_UNDEF
63#endif
64#endif
65
66 if (!cJSON_IsNumber(prop))
67 return NAN;
68 char* val = cJSON_GetStringValue(prop);
69 if (!val)
70 return NAN;
71
72 errno = 0;
73 char* endptr = NULL;
74 double dval = strtod(val, &endptr);
75 if (val == endptr)
76 return NAN;
77 if (endptr != NULL)
78 return NAN;
79 if (errno != 0)
80 return NAN;
81 return dval;
82
83#ifdef COMPAT_NAN_UNDEF
84#undef NAN
85#endif
86}
87
88static cJSON* cJSON_ParseWithLength(const char* value, size_t buffer_length)
89{
90 // Check for string '\0' termination.
91 const size_t slen = strnlen(value, buffer_length);
92 if (slen >= buffer_length)
93 {
94 if (value[buffer_length] != '\0')
95 return NULL;
96 }
97 return cJSON_Parse(value);
98}
99#endif
100
101int WINPR_JSON_version(char* buffer, size_t len)
102{
103#if defined(WITH_JSONC)
104 return _snprintf(buffer, len, "json-c %s", json_c_version());
105#elif defined(WITH_CJSON)
106 return _snprintf(buffer, len, "cJSON %s", cJSON_Version());
107#else
108 (void)_snprintf(buffer, len, "JSON support not available");
109 return -1;
110#endif
111}
112
113WINPR_JSON* WINPR_JSON_Parse(const char* value)
114{
115#if defined(WITH_JSONC)
116 return json_tokener_parse(value);
117#elif defined(WITH_CJSON)
118 return cJSON_Parse(value);
119#else
120 WINPR_UNUSED(value);
121 return NULL;
122#endif
123}
124
125WINPR_JSON* WINPR_JSON_ParseWithLength(const char* value, size_t buffer_length)
126{
127#if defined(WITH_JSONC)
128 WINPR_ASSERT(buffer_length <= INT_MAX);
129 json_tokener* tok = json_tokener_new();
130 if (!tok)
131 return NULL;
132 json_object* obj = json_tokener_parse_ex(tok, value, (int)buffer_length);
133 json_tokener_free(tok);
134 return obj;
135#elif defined(WITH_CJSON)
136 return cJSON_ParseWithLength(value, buffer_length);
137#else
138 WINPR_UNUSED(value);
139 WINPR_UNUSED(buffer_length);
140 return NULL;
141#endif
142}
143
144void WINPR_JSON_Delete(WINPR_JSON* item)
145{
146#if defined(WITH_JSONC)
147 json_object_put((json_object*)item);
148#elif defined(WITH_CJSON)
149 cJSON_Delete((cJSON*)item);
150#else
151 WINPR_UNUSED(item);
152#endif
153}
154
155WINPR_JSON* WINPR_JSON_GetArrayItem(const WINPR_JSON* array, size_t index)
156{
157#if defined(WITH_JSONC)
158 return json_object_array_get_idx((const json_object*)array, index);
159#elif defined(WITH_CJSON)
160 WINPR_ASSERT(index <= INT_MAX);
161 return cJSON_GetArrayItem((const cJSON*)array, (INT)index);
162#else
163 WINPR_UNUSED(array);
164 WINPR_UNUSED(index);
165 return NULL;
166#endif
167}
168
169size_t WINPR_JSON_GetArraySize(const WINPR_JSON* array)
170{
171#if defined(WITH_JSONC)
172 return json_object_array_length((const json_object*)array);
173#elif defined(WITH_CJSON)
174 const int rc = cJSON_GetArraySize((const cJSON*)array);
175 if (rc <= 0)
176 return 0;
177 return (size_t)rc;
178#else
179 WINPR_UNUSED(array);
180 return 0;
181#endif
182}
183
184WINPR_JSON* WINPR_JSON_GetObjectItem(const WINPR_JSON* object, const char* string)
185{
186#if defined(WITH_JSONC)
187 return json_object_object_get((const json_object*)object, string);
188#elif defined(WITH_CJSON)
189 return cJSON_GetObjectItem((const cJSON*)object, string);
190#else
191 WINPR_UNUSED(object);
192 WINPR_UNUSED(string);
193 return NULL;
194#endif
195}
196
197WINPR_JSON* WINPR_JSON_GetObjectItemCaseSensitive(const WINPR_JSON* object, const char* string)
198{
199#if defined(WITH_JSONC)
200 return json_object_object_get((const json_object*)object, string);
201#elif defined(WITH_CJSON)
202 return cJSON_GetObjectItemCaseSensitive((const cJSON*)object, string);
203#else
204 WINPR_UNUSED(object);
205 WINPR_UNUSED(string);
206 return NULL;
207#endif
208}
209
210BOOL WINPR_JSON_HasObjectItem(const WINPR_JSON* object, const char* string)
211{
212#if defined(WITH_JSONC)
213 return json_object_object_get_ex((const json_object*)object, string, NULL);
214#elif defined(WITH_CJSON)
215 return cJSON_HasObjectItem((const cJSON*)object, string);
216#else
217 WINPR_UNUSED(object);
218 WINPR_UNUSED(string);
219 return FALSE;
220#endif
221}
222
223const char* WINPR_JSON_GetErrorPtr(void)
224{
225#if defined(WITH_JSONC)
226 return json_util_get_last_err();
227#elif defined(WITH_CJSON)
228 return cJSON_GetErrorPtr();
229#else
230 return NULL;
231#endif
232}
233
234const char* WINPR_JSON_GetStringValue(WINPR_JSON* item)
235{
236#if defined(WITH_JSONC)
237 return json_object_get_string((json_object*)item);
238#elif defined(WITH_CJSON)
239 return cJSON_GetStringValue((cJSON*)item);
240#else
241 WINPR_UNUSED(item);
242 return NULL;
243#endif
244}
245
246double WINPR_JSON_GetNumberValue(const WINPR_JSON* item)
247{
248#if defined(WITH_JSONC)
249 return json_object_get_double((const json_object*)item);
250#elif defined(WITH_CJSON)
251 return cJSON_GetNumberValue((const cJSON*)item);
252#else
253 WINPR_UNUSED(item);
254 return nan("");
255#endif
256}
257
258BOOL WINPR_JSON_IsInvalid(const WINPR_JSON* item)
259{
260#if defined(WITH_JSONC)
261 if (WINPR_JSON_IsArray(item))
262 return FALSE;
263 if (WINPR_JSON_IsObject(item))
264 return FALSE;
265 if (WINPR_JSON_IsNull(item))
266 return FALSE;
267 if (WINPR_JSON_IsNumber(item))
268 return FALSE;
269 if (WINPR_JSON_IsBool(item))
270 return FALSE;
271 if (WINPR_JSON_IsString(item))
272 return FALSE;
273 return TRUE;
274#elif defined(WITH_CJSON)
275 return cJSON_IsInvalid((const cJSON*)item);
276#else
277 WINPR_UNUSED(item);
278 return TRUE;
279#endif
280}
281
282BOOL WINPR_JSON_IsFalse(const WINPR_JSON* item)
283{
284#if defined(WITH_JSONC)
285 if (!json_object_is_type((const json_object*)item, json_type_boolean))
286 return FALSE;
287 json_bool val = json_object_get_boolean((const json_object*)item);
288 return val == 0;
289#elif defined(WITH_CJSON)
290 return cJSON_IsFalse((const cJSON*)item);
291#else
292 WINPR_UNUSED(item);
293 return FALSE;
294#endif
295}
296
297BOOL WINPR_JSON_IsTrue(const WINPR_JSON* item)
298{
299#if defined(WITH_JSONC)
300 if (!json_object_is_type((const json_object*)item, json_type_boolean))
301 return FALSE;
302 json_bool val = json_object_get_boolean((const json_object*)item);
303 return val != 0;
304#elif defined(WITH_CJSON)
305 return cJSON_IsTrue((const cJSON*)item);
306#else
307 WINPR_UNUSED(item);
308 return FALSE;
309#endif
310}
311
312BOOL WINPR_JSON_IsBool(const WINPR_JSON* item)
313{
314#if defined(WITH_JSONC)
315 return json_object_is_type((const json_object*)item, json_type_boolean);
316#elif defined(WITH_CJSON)
317 return cJSON_IsBool((const cJSON*)item);
318#else
319 WINPR_UNUSED(item);
320 return FALSE;
321#endif
322}
323
324BOOL WINPR_JSON_IsNull(const WINPR_JSON* item)
325{
326#if defined(WITH_JSONC)
327 return json_object_is_type((const json_object*)item, json_type_null);
328#elif defined(WITH_CJSON)
329 return cJSON_IsNull((const cJSON*)item);
330#else
331 WINPR_UNUSED(item);
332 return FALSE;
333#endif
334}
335
336BOOL WINPR_JSON_IsNumber(const WINPR_JSON* item)
337{
338#if defined(WITH_JSONC)
339 return json_object_is_type((const json_object*)item, json_type_int) ||
340 json_object_is_type((const json_object*)item, json_type_double);
341#elif defined(WITH_CJSON)
342 return cJSON_IsNumber((const cJSON*)item);
343#else
344 WINPR_UNUSED(item);
345 return FALSE;
346#endif
347}
348
349BOOL WINPR_JSON_IsString(const WINPR_JSON* item)
350{
351#if defined(WITH_JSONC)
352 return json_object_is_type((const json_object*)item, json_type_string);
353#elif defined(WITH_CJSON)
354 return cJSON_IsString((const cJSON*)item);
355#else
356 WINPR_UNUSED(item);
357 return FALSE;
358#endif
359}
360
361BOOL WINPR_JSON_IsArray(const WINPR_JSON* item)
362{
363#if defined(WITH_JSONC)
364 return json_object_is_type((const json_object*)item, json_type_array);
365#elif defined(WITH_CJSON)
366 return cJSON_IsArray((const cJSON*)item);
367#else
368 WINPR_UNUSED(item);
369 return FALSE;
370#endif
371}
372
373BOOL WINPR_JSON_IsObject(const WINPR_JSON* item)
374{
375#if defined(WITH_JSONC)
376 return json_object_is_type((const json_object*)item, json_type_object);
377#elif defined(WITH_CJSON)
378 return cJSON_IsObject((const cJSON*)item);
379#else
380 WINPR_UNUSED(item);
381 return FALSE;
382#endif
383}
384
385WINPR_JSON* WINPR_JSON_CreateNull(void)
386{
387#if defined(WITH_JSONC)
388 return json_object_new_null();
389#elif defined(WITH_CJSON)
390 return cJSON_CreateNull();
391#else
392 return NULL;
393#endif
394}
395
396WINPR_JSON* WINPR_JSON_CreateTrue(void)
397{
398#if defined(WITH_JSONC)
399 return json_object_new_boolean(TRUE);
400#elif defined(WITH_CJSON)
401 return cJSON_CreateTrue();
402#else
403 return NULL;
404#endif
405}
406
407WINPR_JSON* WINPR_JSON_CreateFalse(void)
408{
409#if defined(WITH_JSONC)
410 return json_object_new_boolean(FALSE);
411#elif defined(WITH_CJSON)
412 return cJSON_CreateFalse();
413#else
414 return NULL;
415#endif
416}
417
418WINPR_JSON* WINPR_JSON_CreateBool(BOOL boolean)
419{
420#if defined(WITH_JSONC)
421 return json_object_new_boolean(boolean);
422#elif defined(WITH_CJSON)
423 return cJSON_CreateBool(boolean);
424#else
425 WINPR_UNUSED(boolean);
426 return NULL;
427#endif
428}
429
430WINPR_JSON* WINPR_JSON_CreateNumber(double num)
431{
432#if defined(WITH_JSONC)
433 return json_object_new_double(num);
434#elif defined(WITH_CJSON)
435 return cJSON_CreateNumber(num);
436#else
437 WINPR_UNUSED(num);
438 return NULL;
439#endif
440}
441
442WINPR_JSON* WINPR_JSON_CreateString(const char* string)
443{
444#if defined(WITH_JSONC)
445 return json_object_new_string(string);
446#elif defined(WITH_CJSON)
447 return cJSON_CreateString(string);
448#else
449 WINPR_UNUSED(string);
450 return NULL;
451#endif
452}
453
454WINPR_JSON* WINPR_JSON_CreateArray(void)
455{
456#if defined(WITH_JSONC)
457 return json_object_new_array();
458#elif defined(WITH_CJSON)
459 return cJSON_CreateArray();
460#else
461 return NULL;
462#endif
463}
464
465WINPR_JSON* WINPR_JSON_CreateObject(void)
466{
467#if defined(WITH_JSONC)
468 return json_object_new_object();
469#elif defined(WITH_CJSON)
470 return cJSON_CreateObject();
471#else
472 return NULL;
473#endif
474}
475
476WINPR_JSON* WINPR_JSON_AddNullToObject(WINPR_JSON* object, const char* name)
477{
478#if defined(WITH_JSONC)
479 struct json_object* obj = json_object_new_null();
480 if (json_object_object_add((json_object*)object, name, obj) != 0)
481 {
482 json_object_put(obj);
483 return NULL;
484 }
485 return obj;
486#elif defined(WITH_CJSON)
487 return cJSON_AddNullToObject((cJSON*)object, name);
488#else
489 WINPR_UNUSED(object);
490 WINPR_UNUSED(name);
491 return NULL;
492#endif
493}
494
495WINPR_JSON* WINPR_JSON_AddTrueToObject(WINPR_JSON* object, const char* name)
496{
497#if defined(WITH_JSONC)
498 struct json_object* obj = json_object_new_boolean(TRUE);
499 if (json_object_object_add((json_object*)object, name, obj) != 0)
500 {
501 json_object_put(obj);
502 return NULL;
503 }
504 return obj;
505#elif defined(WITH_CJSON)
506 return cJSON_AddTrueToObject((cJSON*)object, name);
507#else
508 WINPR_UNUSED(object);
509 WINPR_UNUSED(name);
510 return NULL;
511#endif
512}
513
514WINPR_JSON* WINPR_JSON_AddFalseToObject(WINPR_JSON* object, const char* name)
515{
516#if defined(WITH_JSONC)
517 struct json_object* obj = json_object_new_boolean(FALSE);
518 if (json_object_object_add((json_object*)object, name, obj) != 0)
519 {
520 json_object_put(obj);
521 return NULL;
522 }
523 return obj;
524#elif defined(WITH_CJSON)
525 return cJSON_AddFalseToObject((cJSON*)object, name);
526#else
527 WINPR_UNUSED(object);
528 WINPR_UNUSED(name);
529 return NULL;
530#endif
531}
532
533WINPR_JSON* WINPR_JSON_AddBoolToObject(WINPR_JSON* object, const char* name, BOOL boolean)
534{
535#if defined(WITH_JSONC)
536 struct json_object* obj = json_object_new_boolean(boolean);
537 if (json_object_object_add((json_object*)object, name, obj) != 0)
538 {
539 json_object_put(obj);
540 return NULL;
541 }
542 return obj;
543#elif defined(WITH_CJSON)
544 return cJSON_AddBoolToObject((cJSON*)object, name, boolean);
545#else
546 WINPR_UNUSED(object);
547 WINPR_UNUSED(name);
548 WINPR_UNUSED(boolean);
549 return NULL;
550#endif
551}
552
553WINPR_JSON* WINPR_JSON_AddNumberToObject(WINPR_JSON* object, const char* name, double number)
554{
555#if defined(WITH_JSONC)
556 struct json_object* obj = json_object_new_double(number);
557 if (json_object_object_add((json_object*)object, name, obj) != 0)
558 {
559 json_object_put(obj);
560 return NULL;
561 }
562 return obj;
563#elif defined(WITH_CJSON)
564 return cJSON_AddNumberToObject((cJSON*)object, name, number);
565#else
566 WINPR_UNUSED(object);
567 WINPR_UNUSED(name);
568 WINPR_UNUSED(number);
569 return NULL;
570#endif
571}
572
573WINPR_JSON* WINPR_JSON_AddStringToObject(WINPR_JSON* object, const char* name, const char* string)
574{
575#if defined(WITH_JSONC)
576 struct json_object* obj = json_object_new_string(string);
577 if (json_object_object_add((json_object*)object, name, obj) != 0)
578 {
579 json_object_put(obj);
580 return NULL;
581 }
582 return obj;
583#elif defined(WITH_CJSON)
584 return cJSON_AddStringToObject((cJSON*)object, name, string);
585#else
586 WINPR_UNUSED(object);
587 WINPR_UNUSED(name);
588 WINPR_UNUSED(string);
589 return NULL;
590#endif
591}
592
593WINPR_JSON* WINPR_JSON_AddObjectToObject(WINPR_JSON* object, const char* name)
594{
595#if defined(WITH_JSONC)
596 struct json_object* obj = json_object_new_object();
597 if (json_object_object_add((json_object*)object, name, obj) != 0)
598 {
599 json_object_put(obj);
600 return NULL;
601 }
602 return obj;
603#elif defined(WITH_CJSON)
604 return cJSON_AddObjectToObject((cJSON*)object, name);
605#else
606 WINPR_UNUSED(object);
607 WINPR_UNUSED(name);
608 return NULL;
609#endif
610}
611
612BOOL WINPR_JSON_AddItemToArray(WINPR_JSON* array, WINPR_JSON* item)
613{
614#if defined(WITH_JSONC)
615 const int rc = json_object_array_add((json_object*)array, (json_object*)item);
616 if (rc != 0)
617 return FALSE;
618 return TRUE;
619#elif defined(WITH_CJSON)
620#if defined(USE_CJSON_COMPAT)
621 if ((array == NULL) || (item == NULL))
622 return FALSE;
623 cJSON_AddItemToArray((cJSON*)array, (cJSON*)item);
624 return TRUE;
625#else
626 return cJSON_AddItemToArray((cJSON*)array, (cJSON*)item);
627#endif
628#else
629 WINPR_UNUSED(array);
630 WINPR_UNUSED(item);
631 return FALSE;
632#endif
633}
634
635WINPR_JSON* WINPR_JSON_AddArrayToObject(WINPR_JSON* object, const char* name)
636{
637#if defined(WITH_JSONC)
638 struct json_object* obj = json_object_new_array();
639 if (json_object_object_add((json_object*)object, name, obj) != 0)
640 {
641 json_object_put(obj);
642 return NULL;
643 }
644 return obj;
645#elif defined(WITH_CJSON)
646 return cJSON_AddArrayToObject((cJSON*)object, name);
647#else
648 WINPR_UNUSED(object);
649 WINPR_UNUSED(name);
650 return NULL;
651#endif
652}
653
654char* WINPR_JSON_Print(WINPR_JSON* item)
655{
656#if defined(WITH_JSONC)
657 const char* str = json_object_to_json_string_ext((json_object*)item, JSON_C_TO_STRING_PRETTY);
658 if (!str)
659 return NULL;
660 return _strdup(str);
661#elif defined(WITH_CJSON)
662 return cJSON_Print((const cJSON*)item);
663#else
664 WINPR_UNUSED(item);
665 return NULL;
666#endif
667}
668
669char* WINPR_JSON_PrintUnformatted(WINPR_JSON* item)
670{
671#if defined(WITH_JSONC)
672 const char* str = json_object_to_json_string_ext((json_object*)item, JSON_C_TO_STRING_PLAIN);
673 if (!str)
674 return NULL;
675 return _strdup(str);
676#elif defined(WITH_CJSON)
677 return cJSON_PrintUnformatted((const cJSON*)item);
678#else
679 WINPR_UNUSED(item);
680 return NULL;
681#endif
682}
683
684WINPR_JSON* WINPR_JSON_ParseFromFile(const char* filename)
685{
686 FILE* fp = winpr_fopen(filename, "r");
687 if (!fp)
688 return NULL;
689 WINPR_JSON* json = WINPR_JSON_ParseFromFileFP(fp);
690 (void)fclose(fp);
691 return json;
692}
693
694WINPR_JSON* WINPR_JSON_ParseFromFileFP(FILE* fp)
695{
696 if (!fp)
697 return NULL;
698
699 if (fseek(fp, 0, SEEK_END) != 0)
700 return NULL;
701
702 const INT64 size = _ftelli64(fp);
703 if (size < 0)
704 return NULL;
705
706 if (fseek(fp, 0, SEEK_SET) != 0)
707 return NULL;
708
709 const size_t usize = WINPR_ASSERTING_INT_CAST(size_t, size);
710 char* str = calloc(usize + 1, sizeof(char));
711 if (!str)
712 return NULL;
713
714 WINPR_JSON* json = NULL;
715 const size_t s = fread(str, sizeof(char), usize, fp);
716 if (s == usize)
717 json = WINPR_JSON_ParseWithLength(str, usize);
718 free(str);
719 return json;
720}
WINPR_JSON * WINPR_JSON_CreateBool(BOOL boolean)
WINPR_JSON_CreateBool.
Definition json.c:418
WINPR_JSON * WINPR_JSON_CreateString(const char *string)
WINPR_JSON_CreateString.
Definition json.c:442
BOOL WINPR_JSON_HasObjectItem(const WINPR_JSON *object, const char *string)
Check if JSON has an object matching the name.
Definition json.c:210
WINPR_JSON * WINPR_JSON_AddNumberToObject(WINPR_JSON *object, const char *name, double number)
WINPR_JSON_AddNumberToObject.
Definition json.c:553
WINPR_JSON * WINPR_JSON_ParseFromFileFP(FILE *fp)
Parse a JSON string read from a FILE.
Definition json.c:694
BOOL WINPR_JSON_IsNull(const WINPR_JSON *item)
Check if JSON item is Null.
Definition json.c:324
WINPR_JSON * WINPR_JSON_GetObjectItem(const WINPR_JSON *object, const char *string)
Return a pointer to an JSON object item.
Definition json.c:184
BOOL WINPR_JSON_IsString(const WINPR_JSON *item)
Check if JSON item is of type String.
Definition json.c:349
BOOL WINPR_JSON_AddItemToArray(WINPR_JSON *array, WINPR_JSON *item)
Add an item to an existing array.
Definition json.c:612
WINPR_JSON * WINPR_JSON_AddArrayToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddArrayToObject.
Definition json.c:635
BOOL WINPR_JSON_IsBool(const WINPR_JSON *item)
Check if JSON item is of type BOOL.
Definition json.c:312
double WINPR_JSON_GetNumberValue(const WINPR_JSON *item)
Return the Number value of a JSON item.
Definition json.c:246
WINPR_JSON * WINPR_JSON_AddTrueToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddTrueToObject.
Definition json.c:495
WINPR_JSON * WINPR_JSON_CreateObject(void)
WINPR_JSON_CreateObject.
Definition json.c:465
WINPR_JSON * WINPR_JSON_CreateArray(void)
WINPR_JSON_CreateArray.
Definition json.c:454
int WINPR_JSON_version(char *buffer, size_t len)
Get the library version string.
Definition json.c:101
char * WINPR_JSON_Print(WINPR_JSON *item)
Serialize a JSON instance to string for minimal size without formatting see WINPR_JSON_PrintUnformatt...
Definition json.c:654
WINPR_JSON * WINPR_JSON_AddFalseToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddFalseToObject.
Definition json.c:514
WINPR_JSON * WINPR_JSON_ParseFromFile(const char *filename)
Parse a JSON string read from a file filename.
Definition json.c:684
BOOL WINPR_JSON_IsNumber(const WINPR_JSON *item)
Check if JSON item is of type Number.
Definition json.c:336
WINPR_JSON * WINPR_JSON_GetArrayItem(const WINPR_JSON *array, size_t index)
Return a pointer to an item in the array.
Definition json.c:155
WINPR_JSON * WINPR_JSON_GetObjectItemCaseSensitive(const WINPR_JSON *object, const char *string)
Same as WINPR_JSON_GetObjectItem but with case insensitive matching.
Definition json.c:197
WINPR_JSON * WINPR_JSON_AddStringToObject(WINPR_JSON *object, const char *name, const char *string)
WINPR_JSON_AddStringToObject.
Definition json.c:573
WINPR_JSON * WINPR_JSON_ParseWithLength(const char *value, size_t buffer_length)
Parse a JSON string.
Definition json.c:125
WINPR_JSON * WINPR_JSON_CreateFalse(void)
WINPR_JSON_CreateFalse.
Definition json.c:407
WINPR_JSON * WINPR_JSON_CreateNumber(double num)
WINPR_JSON_CreateNumber.
Definition json.c:430
BOOL WINPR_JSON_IsObject(const WINPR_JSON *item)
Check if JSON item is of type Object.
Definition json.c:373
WINPR_JSON * WINPR_JSON_AddBoolToObject(WINPR_JSON *object, const char *name, BOOL boolean)
WINPR_JSON_AddBoolToObject.
Definition json.c:533
BOOL WINPR_JSON_IsInvalid(const WINPR_JSON *item)
Check if JSON item is valid.
Definition json.c:258
char * WINPR_JSON_PrintUnformatted(WINPR_JSON *item)
Serialize a JSON instance to string without formatting for human readable formatted output see WINPR_...
Definition json.c:669
WINPR_JSON * WINPR_JSON_CreateNull(void)
WINPR_JSON_CreateNull.
Definition json.c:385
const char * WINPR_JSON_GetStringValue(WINPR_JSON *item)
Return the String value of a JSON item.
Definition json.c:234
WINPR_JSON * WINPR_JSON_AddNullToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddNullToObject.
Definition json.c:476
WINPR_JSON * WINPR_JSON_CreateTrue(void)
WINPR_JSON_CreateTrue.
Definition json.c:396
BOOL WINPR_JSON_IsFalse(const WINPR_JSON *item)
Check if JSON item is BOOL value False.
Definition json.c:282
void WINPR_JSON_Delete(WINPR_JSON *item)
Delete a WinPR JSON wrapper object.
Definition json.c:144
size_t WINPR_JSON_GetArraySize(const WINPR_JSON *array)
Get the number of arrayitems from an array.
Definition json.c:169
BOOL WINPR_JSON_IsArray(const WINPR_JSON *item)
Check if JSON item is of type Array.
Definition json.c:361
const char * WINPR_JSON_GetErrorPtr(void)
Return an error string.
Definition json.c:223
WINPR_JSON * WINPR_JSON_AddObjectToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddObjectToObject.
Definition json.c:593
WINPR_JSON * WINPR_JSON_Parse(const char *value)
Parse a '\0' terminated JSON string.
Definition json.c:113
BOOL WINPR_JSON_IsTrue(const WINPR_JSON *item)
Check if JSON item is BOOL value True.
Definition json.c:297