-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjson.inc
More file actions
executable file
·2382 lines (2184 loc) · 83.7 KB
/
Copy pathjson.inc
File metadata and controls
executable file
·2382 lines (2184 loc) · 83.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if defined _json_included
#endinput
#endif
#define _json_included
// JSON value types
enum JSON_TYPE
{
JSON_TYPE_NONE = 0, // Invalid type
JSON_TYPE_RAW = 1, // Raw string (stored as is, used for number/literal)
JSON_TYPE_NULL = 2, // null
JSON_TYPE_BOOL = 3, // true/false
JSON_TYPE_NUM = 4, // Number (integer/real)
JSON_TYPE_STR = 5, // String
JSON_TYPE_ARR = 6, // Array
JSON_TYPE_OBJ = 7 // Object
}
// JSON value subtypes
enum JSON_SUBTYPE
{
JSON_SUBTYPE_NONE = 0 << 3, // Invalid subtype
JSON_SUBTYPE_FALSE = 0 << 3, // Boolean false
JSON_SUBTYPE_TRUE = 1 << 3, // Boolean true
JSON_SUBTYPE_UINT = 0 << 3, // Unsigned integer
JSON_SUBTYPE_SINT = 1 << 3, // Signed integer
JSON_SUBTYPE_REAL = 2 << 3, // Real number (float/double)
JSON_SUBTYPE_NOESC = 1 << 3 // String without escape character
}
// JSON reader flags for parsing behavior
enum JSON_READ_FLAG
{
JSON_READ_NOFLAG = 0 << 0, // Default behavior
JSON_READ_INSITU = 1 << 0, // Read JSON data in-situ (modify input string)
JSON_READ_STOP_WHEN_DONE = 1 << 1, // Stop when done instead of issuing an error if there's additional content
JSON_READ_ALLOW_TRAILING_COMMAS = 1 << 2, // Allow trailing commas at the end of arrays/objects
JSON_READ_ALLOW_COMMENTS = 1 << 3, // Allow C-style comments (/* */) and line comments (//)
JSON_READ_ALLOW_INF_AND_NAN = 1 << 4, // Allow nan/inf number (non-standard JSON)
JSON_READ_NUMBER_AS_RAW = 1 << 5, // Read numbers as raw strings
JSON_READ_ALLOW_INVALID_UNICODE = 1 << 6, // Allow invalid unicode when parsing string
JSON_READ_BIGNUM_AS_RAW = 1 << 7, // Read big numbers as raw strings
JSON_READ_ALLOW_BOM = 1 << 8, // Allow BOM (Byte Order Mark) at the beginning of the JSON string
JSON_READ_ALLOW_EXT_NUMBER = 1 << 9, // Allow extended number (non-standard JSON)
JSON_READ_ALLOW_EXT_ESCAPE = 1 << 10, // Allow extended escape sequences in strings (non-standard)
JSON_READ_ALLOW_EXT_WHITESPACE = 1 << 11, // Allow extended whitespace characters (non-standard)
JSON_READ_ALLOW_SINGLE_QUOTED_STR = 1 << 12, // Allow strings enclosed in single quotes (non-standard)
JSON_READ_ALLOW_UNQUOTED_KEY = 1 << 13, // Allow object keys without quotes (non-standard)
JSON_READ_JSON5 = JSON_READ_ALLOW_TRAILING_COMMAS |
JSON_READ_ALLOW_COMMENTS |
JSON_READ_ALLOW_INF_AND_NAN |
JSON_READ_ALLOW_EXT_NUMBER |
JSON_READ_ALLOW_EXT_ESCAPE |
JSON_READ_ALLOW_EXT_WHITESPACE |
JSON_READ_ALLOW_SINGLE_QUOTED_STR |
JSON_READ_ALLOW_UNQUOTED_KEY // Allow JSON5 format, see: [https://json5.org]
}
// JSON writer flags for serialization behavior
enum JSON_WRITE_FLAG
{
JSON_WRITE_NOFLAG = 0 << 0, // Default behavior
JSON_WRITE_PRETTY = 1 << 0, // Pretty print with indent and newline
JSON_WRITE_ESCAPE_UNICODE = 1 << 1, // Escape unicode as \uXXXX
JSON_WRITE_ESCAPE_SLASHES = 1 << 2, // Escape '/' as '\/'
JSON_WRITE_ALLOW_INF_AND_NAN = 1 << 3, // Write inf/nan number (non-standard JSON)
JSON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4, // Write inf/nan as null
JSON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5, // Allow invalid unicode when encoding string
JSON_WRITE_PRETTY_TWO_SPACES = 1 << 6, // Use 2 spaces for indent when pretty print
JSON_WRITE_NEWLINE_AT_END = 1 << 7, // Add newline at the end of output
JSON_WRITE_FP_TO_FLOAT = 1 << 27 // Write floating-point numbers using single-precision (float)
}
/**
* Write floating-point number using fixed-point notation
* This is similar to ECMAScript Number.prototype.toFixed(prec) but with trailing zeros removed
*
* @param n Precision digits (1-7)
* @return JSON write flag with precision setting
* @note This will produce shorter output but may lose some precision
*/
stock JSON_WRITE_FLAG JSON_WRITE_FP_TO_FIXED(int n)
{
n = (n < 1) ? 1 : (n > 7 ? 7 : n);
return view_as<JSON_WRITE_FLAG>(n << 28);
}
// Sort order for arrays and objects
enum JSON_SORT_ORDER
{
JSON_SORT_ASC = 0, // Ascending order (default)
JSON_SORT_DESC = 1, // Descending order
JSON_SORT_RANDOM = 2 // Random order
}
methodmap JSON < Handle
{
/**
* Creates a JSON value using a format string and arguments
* Format specifiers:
* - s: string
* - i: integer
* - f: float
* - b: boolean
* - n: null
* - {: start object
* - }: end object
* - [: start array
* - ]: end array
*
* @note Needs to be freed using delete or CloseHandle()
* @note SourcePawn imposes a limit of 32 parameters per function (defined by SP_MAX_EXEC_PARAMS),
* which precludes the construction of complex objects with this method.
*
* @param format Format string
* @param ... Arguments based on format string
*
* @return JSON handle
* @error If format string is invalid or arguments don't match
*/
public static native any Pack(const char[] format, any ...);
/**
* Converts an immutable JSON document to a mutable one
*
* @note Needs to be freed using delete or CloseHandle()
* @note Creates a deep copy as a mutable document
*
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return Handle to the new mutable JSON document, null if already mutable or on error
*/
public native any ToMutable(char[] error = "", int error_size = 0);
/**
* Converts a mutable JSON document to an immutable one
*
* @note Needs to be freed using delete or CloseHandle()
* @note Creates a deep copy as an immutable document
*
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return Handle to the new immutable JSON document, null if already immutable or on error
*/
public native any ToImmutable(char[] error = "", int error_size = 0);
/**
* Apply a JSON Patch (RFC 6902) to this value and return a new JSON handle
*
* @note Needs to be freed using delete or CloseHandle()
*
* @param patch JSON Patch document
* @param resultMutable True to return a mutable result, false for immutable
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return New JSON handle on success, null on failure
*/
public native any ApplyJsonPatch(const JSON patch, bool resultMutable = false, char[] error = "", int error_size = 0);
/**
* Apply a JSON Patch (RFC 6902) to this value in place
*
* @param patch JSON Patch document
*
* @return True on success, false otherwise
* @error Throws if this value is immutable or patch failed
*/
public native bool JsonPatchInPlace(const JSON patch);
/**
* Apply a JSON Merge Patch (RFC 7396) to this value and return a new JSON handle
*
* @note Needs to be freed using delete or CloseHandle()
*
* @param patch JSON Merge Patch document
* @param resultMutable True to return a mutable result, false for immutable
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return New JSON handle on success, null on failure
*/
public native any ApplyMergePatch(const JSON patch, bool resultMutable = false, char[] error = "", int error_size = 0);
/**
* Apply a JSON Merge Patch (RFC 7396) to this value in place
*
* @param patch JSON Merge Patch document
*
* @return True on success, false otherwise
* @error Throws if this value is immutable or merge patch failed
*/
public native bool MergePatchInPlace(const JSON patch);
/**
* Write a document to JSON file with options
*
* @note On 32-bit operating system, files larger than 2GB may fail to write
*
* @param file The JSON file's path. If this path is null or invalid, the function will fail and return false.
* If this file is not empty, the content will be discarded
* @param flag The JSON write options
*
* @return True on success, false on failure
*/
public native bool ToFile(const char[] file, JSON_WRITE_FLAG flag = JSON_WRITE_NOFLAG);
/**
* Write a value to JSON string
*
* @param buffer String buffer to write to
* @param maxlength Maximum length of the string buffer
* @param flag The JSON write options
*
* @return Number of characters written to the buffer (including null terminator) or 0 on failure
*/
public native int ToString(char[] buffer, int maxlength, JSON_WRITE_FLAG flag = JSON_WRITE_NOFLAG);
/**
* Write JSON to string buffer (zero-allocation version)
*
* @note This is a zero-allocation version that writes directly to the buffer
* @note Provides approximately 15% better performance compared to ToString()
* @note The buffer must be large enough to accommodate temporary formatting space:
* - Number: 40 bytes
* - String: 16 + (str_len * 6) bytes
* - Other values: 16 bytes
* - Nesting depth: 16 * max_json_depth bytes
* @note GetSerializedSize() only returns the final JSON size, NOT including the temporary space.
* For most use cases, prefer ToString() for simplicity
*
* @param buffer String buffer to write to
* @param maxlength Maximum length of the string buffer
* @param flag The JSON write options
*
* @return Number of characters written to the buffer (including null terminator) or 0 on failure
* @error Invalid handle or buffer too small
*/
public native int ToStringDirect(char[] buffer, int maxlength, JSON_WRITE_FLAG flag = JSON_WRITE_NOFLAG);
/**
* Write a JSON number value to string buffer
*
* @note The buffer must be large enough to hold the number string (at least 40 bytes for floating-point, 21 bytes for integer)
*
* @param buffer String buffer to write to
* @param maxlength Maximum length of the string buffer
* @param written Variable to store number of characters written (excluding null terminator) (optional)
*
* @return True on success, false on failure
* @error Invalid handle, handle is not a number, or buffer too small
*/
public native bool WriteNumber(char[] buffer, int maxlength, int &written = 0);
/**
* Set floating-point number's output format to single-precision
*
* @note Only works on floating-point numbers (not integers)
* @note This affects how the number is serialized in all write operations
*
* @param flt True to use single-precision (float), false to use double-precision (double)
*
* @return True on success, false if handle is not a floating-point number
* @error Invalid handle or handle is not a floating-point number
*/
public native bool SetFpToFloat(bool flt);
/**
* Set floating-point number's output format to fixed-point notation
*
* @note Only works on floating-point numbers (not integers)
* @note This is similar to ECMAScript Number.prototype.toFixed(prec) but with trailing zeros removed
* @note This will produce shorter output but may lose some precision
* @note This affects how the number is serialized in all write operations
*
* @param prec Precision (1-7)
*
* @return True on success, false if handle is not a floating-point number or prec is out of range
* @error Invalid handle, handle is not a floating-point number, or precision out of range (1-7)
*/
public native bool SetFpToFixed(int prec);
/**
* Directly modify a JSON value to boolean type
*
* @note This modifies the value in-place without creating a new value
* @warning For immutable documents, this breaks immutability. Use with caution
*
* @param value Boolean value
*
* @return True on success, false if value is object or array
* @error Invalid handle or handle is object or array
*/
public native bool SetBool(bool value);
/**
* Directly modify a JSON value to integer type
*
* @note This modifies the value in-place without creating a new value
* @warning For immutable documents, this breaks immutability. Use with caution
*
* @param value Integer value
*
* @return True on success, false if value is object or array
* @error Invalid handle or handle is object or array
*/
public native bool SetInt(int value);
/**
* Directly modify a JSON value to 64-bit integer type
*
* @note This modifies the value in-place without creating a new value
* @warning For immutable documents, this breaks immutability. Use with caution
* @note This function auto-detects whether the value is signed or unsigned
*
* @param value 64-bit integer value (as string, can be signed or unsigned)
*
* @return True on success, false if value is object or array
* @error Invalid handle, handle is object or array, or invalid int64 string format
*/
public native bool SetInt64(const char[] value);
/**
* Directly modify a JSON value to floating-point type
*
* @note This modifies the value in-place without creating a new value
* @warning For immutable documents, this breaks immutability. Use with caution
*
* @param value Float value
*
* @return True on success, false if value is object or array
* @error Invalid handle or handle is object or array
*/
public native bool SetFloat(float value);
/**
* Directly modify a JSON value to string type
*
* @note This modifies the value in-place without creating a new value
* @note For mutable documents, the string is copied into the document's memory pool
* @warning For immutable documents, this breaks immutability and does NOT copy the string. Use with caution
* @warning For immutable documents, the string pointer must remain valid for the document's lifetime
*
* @param value String value
*
* @return True on success, false if value is object or array or value is null
* @error Invalid handle or handle is object or array
*/
public native bool SetString(const char[] value);
/**
* Directly modify a JSON value to null type
*
* @note This modifies the value in-place without creating a new value
* @warning For immutable documents, this breaks immutability. Use with caution
*
* @return True on success, false if value is object or array
* @error Invalid handle or handle is object or array
*/
public native bool SetNull();
/**
* Parses JSON string or a file that contains JSON
*
* @note Needs to be freed using delete or CloseHandle()
*
* @param string String or file to parse
* @param is_file True to treat string param as file, false otherwise
* @param is_mutable_doc True to create a mutable document, false to create an immutable one
* @param flag The JSON read options
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return JSON handle, null on failure
*/
public static native any Parse(const char[] string, bool is_file = false, bool is_mutable_doc = false, JSON_READ_FLAG flag = JSON_READ_NOFLAG, char[] error = "", int error_size = 0);
/**
* Read a JSON number from string
*
* @note Needs to be freed using delete or CloseHandle()
* @note The input string must be null-terminated UTF-8 without BOM
* @note The returned value is a mutable number value
*
* @param dat The JSON data (UTF-8 without BOM), null-terminator is required
* @param flag Read flags (JSON_READ_FLAG values, default: JSON_READ_NOFLAG)
* @param consumed Variable to store number of characters consumed (optional)
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return New JSON number value, null on failure
*/
public static native JSON ReadNumber(const char[] dat, JSON_READ_FLAG flag = JSON_READ_NOFLAG, int &consumed = 0, char[] error = "", int error_size = 0);
/**
* Creates a deep copy of a JSON value and returns it as a new JSON handle
*
* @note Needs to be freed using delete or CloseHandle()
* @note The returned value is owned by targetDoc's document context
* @note The mutability of the returned copy depends on the targetDoc parameter
* @warning This function is recursive and may cause a stack overflow if the object level is too deep
*
* @param targetDoc The target document that determines whether the copy will be mutable or immutable
* @param sourceValue The source JSON value to be copied
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return New JSON handle on success, null on failure
*/
public static native any DeepCopy(const JSON targetDoc, const JSON sourceValue, char[] error = "", int error_size = 0);
/**
* Returns the JSON value's type description
*
* @param buffer String buffer to write to
* @param maxlength Maximum length of the string buffer
*
* @return The return value should be one of these strings: "raw", "null", "string",
* "array", "object", "true", "false", "uint", "sint", "real", "unknown"
*/
public native void GetTypeDesc(char[] buffer, int maxlength);
/**
* Returns whether two JSON values are equal (deep compare)
*
* @note This function is recursive and may cause a stack overflow if the object level is too deep
* @note the result may be inaccurate if object has duplicate keys
*
* @param value1 First JSON value to compare
* @param value2 Second JSON value to compare
*
* @return True if they are the same, false otherwise
*/
public static native bool Equals(const JSON value1, const JSON value2);
/**
* Check if JSON value equals a string
*
* @param value JSON handle
* @param str String to compare with
*
* @return True if value is a string and equals the given string, false otherwise
*/
public static native bool EqualsStr(const JSON value, const char[] str);
/**
* Creates and returns a boolean value
*
* @note Needs to be freed using delete or CloseHandle()
*
* @param value The boolean value to be set
*
* @return JSON handle
*/
public static native JSON CreateBool(bool value);
/**
* Creates and returns a float value
*
* @note Needs to be freed using delete or CloseHandle()
*
* @param value The float value to be set
*
* @return JSON handle
*/
public static native JSON CreateFloat(float value);
/**
* Creates and returns an int value
*
* @note Needs to be freed using delete or CloseHandle()
*
* @param value The int value to be set
*
* @return JSON handle
*/
public static native JSON CreateInt(int value);
/**
* Creates and returns an integer64 value
*
* @note Needs to be freed using delete or CloseHandle()
* @note This function auto-detects whether the value is signed or unsigned
*
* @param value The integer64 value to be set (can be signed or unsigned)
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return JSON handle
*/
public static native JSON CreateInt64(const char[] value, char[] error = "", int error_size = 0);
/**
* Creates and returns a string value
*
* @note Needs to be freed using delete or CloseHandle()
*
* @param value The string value to be set
*
* @return JSON handle
*/
public static native JSON CreateString(const char[] value);
/**
* Creates and returns a null value
*
* @note Needs to be freed using delete or CloseHandle()
*
* @return JSON handle
*/
public static native JSON CreateNull();
/**
* Get boolean value
*
* @return Boolean value
*/
public native bool GetBool();
/**
* Get float value
*
* @note Integers values are auto converted to float
*
* @return float value
*/
public native float GetFloat();
/**
* Get int value
*
* @return int value
*/
public native int GetInt();
/**
* Get integer64 value (auto-detects signed/unsigned)
*
* @param buffer Buffer to copy to
* @param maxlength Maximum size of the buffer
*
* @return True on success, false on failure
*/
public native bool GetInt64(char[] buffer, int maxlength);
/**
* Get string value
*
* @param buffer Buffer to copy to
* @param maxlength Maximum size of the buffer
*
* @return True on success, false on failure
*/
public native bool GetString(char[] buffer, int maxlength);
/**
* Get JSON Handle serialized size in bytes (including null-terminator)
*
* @param flag The JSON write options
*
* @return Size in bytes (including null terminator)
*
* @note The returned size depends on the flag parameter.
* You MUST use the same flags when calling both GetSerializedSize()
* and ToString(). Using different flags will return different sizes
* and may cause buffer overflow
*/
public native int GetSerializedSize(JSON_WRITE_FLAG flag = JSON_WRITE_NOFLAG);
/**
* Get value by a JSON Pointer
*
* @note Needs to be freed using delete or CloseHandle()
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param error Optional buffer to store error message
* @param error_size Size of error buffer
*
* @return The value referenced by the JSON pointer, null on failure
*/
public native any PtrGet(const char[] path, char[] error = "", int error_size = 0);
/**
* Get boolean value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
*
* @return boolean value referenced by the JSON pointer
*/
public native bool PtrGetBool(const char[] path);
/**
* Get float value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note Integers values are auto converted to float
*
* @param path The JSON pointer string
*
* @return float value referenced by the JSON pointer
*/
public native float PtrGetFloat(const char[] path);
/**
* Get integer value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
*
* @return integer value referenced by the JSON pointer
*/
public native int PtrGetInt(const char[] path);
/**
* Get integer64 value by a JSON Pointer (auto-detects signed/unsigned)
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param buffer Buffer to copy to
* @param maxlength Maximum size of the buffer
*
* @return True on success, false on failure
*/
public native bool PtrGetInt64(const char[] path, char[] buffer, int maxlength);
/**
* Get string value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param buffer Buffer to copy to
* @param maxlength Maximum size of the buffer
*
* @return True on success, false on failure
*/
public native bool PtrGetString(const char[] path, char[] buffer, int maxlength);
/**
* Get value is null by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
*
* @return True if the value is null, false otherwise
*/
public native bool PtrGetIsNull(const char[] path);
/**
* Get JSON content length (string length, array size, object size)
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note For strings: returns string length including null-terminator
* @note For arrays/objects: returns number of elements
* @note Returns 0 if value is null or type is not string/array/object
*
* @param path The JSON pointer string
*
* @return JSON content length
*/
public native int PtrGetLength(const char[] path);
/**
* Set value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note The parent nodes will be created if they do not exist.
* If the target value already exists, it will be replaced by the new value
*
* @param path The JSON pointer string
* @param value The value to be set
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrSet(const char[] path, JSON value);
/**
* Set boolean value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note The parent nodes will be created if they do not exist.
* If the target value already exists, it will be replaced by the new value
*
* @param path The JSON pointer string
* @param value The boolean value to be set
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrSetBool(const char[] path, bool value);
/**
* Set float value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note The parent nodes will be created if they do not exist.
* If the target value already exists, it will be replaced by the new value
*
* @param path The JSON pointer string
* @param value The float value to be set
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrSetFloat(const char[] path, float value);
/**
* Set integer value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note The parent nodes will be created if they do not exist.
* If the target value already exists, it will be replaced by the new value
*
* @param path The JSON pointer string
* @param value The integer value to be set
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrSetInt(const char[] path, int value);
/**
* Set integer64 value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note The parent nodes will be created if they do not exist.
* If the target value already exists, it will be replaced by the new value
* @note This function auto-detects whether the value is signed or unsigned
*
* @param path The JSON pointer string
* @param value The integer64 value to be set (can be signed or unsigned)
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrSetInt64(const char[] path, const char[] value);
/**
* Set string value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note The parent nodes will be created if they do not exist.
* If the target value already exists, it will be replaced by the new value
*
* @param path The JSON pointer string
* @param value The string value to be set
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrSetString(const char[] path, const char[] value);
/**
* Set null value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note The parent nodes will be created if they do not exist.
* If the target value already exists, it will be replaced by the new value
*
* @param path The JSON pointer string
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrSetNull(const char[] path);
/**
* Add (insert) value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value The value to be added
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrAdd(const char[] path, JSON value);
/**
* Add (insert) boolean value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value The boolean value to be added
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrAddBool(const char[] path, bool value);
/**
* Add (insert) float value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value The float value to be added
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrAddFloat(const char[] path, float value);
/**
* Add (insert) integer value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value The int value to be added
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrAddInt(const char[] path, int value);
/**
* Add (insert) integer64 value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value The integer64 value to be added
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrAddInt64(const char[] path, const char[] value);
/**
* Add (insert) string value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value The str value to be added
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrAddString(const char[] path, const char[] value);
/**
* Add (insert) null value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
*
* @return true if JSON pointer is valid and new value is set, false otherwise
*/
public native bool PtrAddNull(const char[] path);
/**
* Remove value by a JSON pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
*
* @return true if removed value, false otherwise
*/
public native bool PtrRemove(const char[] path);
/**
* Try to get boolean value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value Store the boolean value
*
* @return true on success, false otherwise
*/
public native bool PtrTryGetBool(const char[] path, bool &value);
/**
* Try to get float value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
* @note Integers values are auto converted to float
*
* @param path The JSON pointer string
* @param value Store the float value
*
* @return true on success, false otherwise
*/
public native bool PtrTryGetFloat(const char[] path, float &value);
/**
* Try to get integer value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param value Store the integer value
*
* @return true on success, false otherwise
*/
public native bool PtrTryGetInt(const char[] path, int &value);
/**
* Try to get integer64 value by a JSON Pointer (automatically detects signed/unsigned)
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param buffer Buffer to store the integer64 value
* @param maxlength Maximum length of the buffer
*
* @return true on success, false otherwise
*/
public native bool PtrTryGetInt64(const char[] path, char[] buffer, int maxlength);
/**
* Try to get string value by a JSON Pointer
*
* @note JSON Pointer paths are always resolved from the document root, not from the current value
*
* @param path The JSON pointer string
* @param buffer Buffer to store the string value
* @param maxlength Maximum length of the buffer
*
* @return true on success, false otherwise
*/
public native bool PtrTryGetString(const char[] path, char[] buffer, int maxlength);
/**
* Retrieves json type
*/
property JSON_TYPE Type {
public native get();
}
/**
* Retrieves json subtype
*/
property JSON_SUBTYPE SubType {
public native get();
}
/**
* Retrieves json is array
*/
property bool IsArray {
public native get();
}
/**
* Retrieves json is object
*/
property bool IsObject {
public native get();
}
/**
* Retrieves json is integer (uint64_t/int64_t)
*/
property bool IsInt {
public native get();
}
/**
* Retrieves json is unsigned integer (uint64_t)
*/
property bool IsUint {
public native get();
}
/**
* Retrieves json is signed integer (int64_t)
*/
property bool IsSint {
public native get();
}
/**
* Retrieves json is number (uint64_t/int64_t/double)
*/
property bool IsNum {
public native get();
}
/**
* Retrieves json is boolean
*/
property bool IsBool {
public native get();
}
/**
* Retrieves json is true
*/
property bool IsTrue {
public native get();
}
/**
* Retrieves json is false
*/
property bool IsFalse {
public native get();