-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJson-1.0.d.ts
3048 lines (2990 loc) · 105 KB
/
Json-1.0.d.ts
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
/** Generated with https://github.com/Gr3q/GIR2TS - If possible do not modify. */
declare namespace imports.gi.Json {
/** This construct is only for enabling class multi-inheritance,
* use {@link Builder} instead.
*/
interface IBuilder {
/**
* Whether the tree should be immutable when created.
*
* Making the output immutable on creation avoids the expense
* of traversing it to make it immutable later.
*/
immutable: boolean;
/**
* Adds a boolean value to the currently open object member or array.
*
* If called after [method#Json.Builder.set_member_name], sets the given value
* as the value of the current member in the open object; otherwise, the value
* is appended to the elements of the open array.
*
* See also: [method#Json.Builder.add_value]
* @param value the value of the member or element
* @returns the builder instance
*/
add_boolean_value(value: boolean): Builder | null;
/**
* Adds a floating point value to the currently open object member or array.
*
* If called after [method#Json.Builder.set_member_name], sets the given value
* as the value of the current member in the open object; otherwise, the value
* is appended to the elements of the open array.
*
* See also: [method#Json.Builder.add_value]
* @param value the value of the member or element
* @returns the builder instance
*/
add_double_value(value: number): Builder | null;
/**
* Adds an integer value to the currently open object member or array.
*
* If called after [method#Json.Builder.set_member_name], sets the given value
* as the value of the current member in the open object; otherwise, the value
* is appended to the elements of the open array.
*
* See also: [method#Json.Builder.add_value]
* @param value the value of the member or element
* @returns the builder instance
*/
add_int_value(value: number): Builder | null;
/**
* Adds a null value to the currently open object member or array.
*
* If called after [method#Json.Builder.set_member_name], sets the given value
* as the value of the current member in the open object; otherwise, the value
* is appended to the elements of the open array.
*
* See also: [method#Json.Builder.add_value]
* @returns the builder instance
*/
add_null_value(): Builder | null;
/**
* Adds a boolean value to the currently open object member or array.
*
* If called after [method#Json.Builder.set_member_name], sets the given value
* as the value of the current member in the open object; otherwise, the value
* is appended to the elements of the open array.
*
* See also: [method#Json.Builder.add_value]
* @param value the value of the member or element
* @returns the builder instance
*/
add_string_value(value: string): Builder | null;
/**
* Adds a value to the currently open object member or array.
*
* If called after [method#Json.Builder.set_member_name], sets the given node
* as the value of the current member in the open object; otherwise, the node
* is appended to the elements of the open array.
*
* The builder will take ownership of the node.
* @param node the value of the member or element
* @returns the builder instance
*/
add_value(node: Node): Builder | null;
/**
* Opens an array inside the given builder.
*
* You can add a new element to the array by using [method#Json.Builder.add_value].
*
* Once you added all elements to the array, you must call
* [method#Json.Builder.end_array] to close the array.
* @returns the builder instance
*/
begin_array(): Builder | null;
/**
* Opens an object inside the given builder.
*
* You can add a new member to the object by using [method#Json.Builder.set_member_name],
* followed by [method#Json.Builder.add_value].
*
* Once you added all members to the object, you must call [method#Json.Builder.end_object]
* to close the object.
*
* If the builder is in an inconsistent state, this function will return `NULL`.
* @returns the builder instance
*/
begin_object(): Builder | null;
/**
* Closes the array inside the given builder that was opened by the most
* recent call to [method#Json.Builder.begin_array].
*
* This function cannot be called after [method#Json.Builder.set_member_name].
* @returns the builder instance
*/
end_array(): Builder | null;
/**
* Closes the object inside the given builder that was opened by the most
* recent call to [method#Json.Builder.begin_object].
*
* This function cannot be called after [method#Json.Builder.set_member_name].
* @returns the builder instance
*/
end_object(): Builder | null;
/**
* Returns the root of the currently constructed tree.
*
* if the build is incomplete (ie: if there are any opened objects, or any
* open object members and array elements) then this function will return
* `NULL`.
* @returns the root node
*/
get_root(): Node | null;
/**
* Resets the state of the builder back to its initial state.
*/
reset(): void;
/**
* Sets the name of the member in an object.
*
* This function must be followed by of these functions:
*
* - [method#Json.Builder.add_value], to add a scalar value to the member
* - [method#Json.Builder.begin_object], to add an object to the member
* - [method#Json.Builder.begin_array], to add an array to the member
*
* This function can only be called within an open object.
* @param member_name the name of the member
* @returns the builder instance
*/
set_member_name(member_name: string): Builder | null;
connect(signal: "notify::immutable", callback: (owner: this, ...args: any) => void): number;
}
type BuilderInitOptionsMixin = GObject.ObjectInitOptions &
Pick<IBuilder,
"immutable">;
export interface BuilderInitOptions extends BuilderInitOptionsMixin {}
/** This construct is only for enabling class multi-inheritance,
* use {@link Builder} instead.
*/
type BuilderMixin = IBuilder & GObject.Object;
/**
* `JsonBuilder` provides an object for generating a JSON tree.
*
* The root of the JSON tree can be either a [struct#Json.Object] or a [struct#Json.Array].
* Thus the first call must necessarily be either
* [method#Json.Builder.begin_object] or [method#Json.Builder.begin_array].
*
* For convenience to language bindings, most `JsonBuilder` method return the
* instance, making it easy to chain function calls.
*
* ## Using `JsonBuilder`
*
* ```c
* g_autoptr(JsonBuilder) builder = json_builder_new ();
*
* json_builder_begin_object (builder);
*
* json_builder_set_member_name (builder, "url");
* json_builder_add_string_value (builder, "http://www.gnome.org/img/flash/two-thirty.png");
*
* json_builder_set_member_name (builder, "size");
* json_builder_begin_array (builder);
* json_builder_add_int_value (builder, 652);
* json_builder_add_int_value (builder, 242);
* json_builder_end_array (builder);
*
* json_builder_end_object (builder);
*
* g_autoptr(JsonNode) root = json_builder_get_root (builder);
*
* g_autoptr(JsonGenerator) gen = json_generator_new ();
* json_generator_set_root (gen, root);
* g_autofree char *str = json_generator_to_data (gen, NULL);
*
* // str now contains the following JSON data
* // { "url" : "http://www.gnome.org/img/flash/two-thirty.png", "size" : [ 652, 242 ] }
* ```
*/
interface Builder extends BuilderMixin {}
class Builder {
public constructor(options?: Partial<BuilderInitOptions>);
/**
* Creates a new `JsonBuilder`.
*
* You can use this object to generate a JSON tree and obtain the root node.
* @returns the newly created builder instance
*/
public static new(): Builder;
/**
* Creates a new, immutable `JsonBuilder` instance.
*
* It is equivalent to setting the [property#Json.Builder:immutable] property
* set to `TRUE` at construction time.
* @returns the newly create builder instance
*/
public static new_immutable(): Builder;
}
/** This construct is only for enabling class multi-inheritance,
* use {@link Generator} instead.
*/
interface IGenerator {
/**
* Number of spaces to be used to indent when pretty printing.
*/
indent: number;
/**
* The character that should be used when indenting in pretty print.
*/
indent_char: number;
/**
* Whether the output should be "pretty-printed", with indentation and
* newlines.
*
* The indentation level can be controlled by using the
* [property#Json.Generator:indent] property.
*/
pretty: boolean;
/**
* The root node to be used when constructing a JSON data
* stream.
*/
root: Node;
/**
* Retrieves the value set using [method#Json.Generator.set_indent].
* @returns the number of repetitions per indentation level
*/
get_indent(): number;
/**
* Retrieves the value set using [method#Json.Generator.set_indent_char].
* @returns the character to be used when indenting
*/
get_indent_char(): string;
/**
* Retrieves the value set using [method#Json.Generator.set_pretty].
* @returns `TRUE` if the generated JSON should be pretty-printed, and
* `FALSE` otherwise
*/
get_pretty(): boolean;
/**
* Retrieves a pointer to the root node set using
* [method#Json.Generator.set_root].
* @returns the root node
*/
get_root(): Node | null;
/**
* Sets the number of repetitions for each indentation level.
* @param indent_level the number of repetitions of the indentation character
* that should be applied when pretty printing
*/
set_indent(indent_level: number): void;
/**
* Sets the character to be used when indenting.
* @param indent_char a Unicode character to be used when indenting
*/
set_indent_char(indent_char: string): void;
/**
* Sets whether the generated JSON should be pretty printed.
*
* Pretty printing will use indentation character specified in the
* [property#Json.Generator:indent-char] property and the spacing
* specified in the [property#Json.Generator:indent] property.
* @param is_pretty whether the generated string should be pretty printed
*/
set_pretty(is_pretty: boolean): void;
/**
* Sets the root of the JSON data stream to be serialized by
* the given generator.
*
* The passed `node` is copied by the generator object, so it can be
* safely freed after calling this function.
* @param node the root node
*/
set_root(node: Node): void;
/**
* Generates a JSON data stream from #generator and returns it as a
* buffer.
* @returns a newly allocated string holding a JSON data stream
*
* return location for the length of the returned
* buffer
*/
to_data(): [ string, number | null ];
/**
* Creates a JSON data stream and puts it inside `filename`, overwriting
* the file's current contents.
*
* This operation is atomic, in the sense that the data is written to a
* temporary file which is then renamed to the given `filename`.
* @param filename the path to the target file
* @returns %TRUE if saving was successful.
*/
to_file(filename: string): boolean;
/**
* Generates a JSON data stream and appends it to the string buffer.
* @param string a string buffer
* @returns the passed string, updated with
* the generated JSON data
*/
to_gstring(string: GLib.String): GLib.String;
/**
* Outputs JSON data and writes it (synchronously) to the given stream.
* @param stream the output stream used to write the JSON data
* @param cancellable a `GCancellable`
* @returns whether the write operation was successful
*/
to_stream(stream: Gio.OutputStream, cancellable?: Gio.Cancellable | null): boolean;
connect(signal: "notify::indent", callback: (owner: this, ...args: any) => void): number;
connect(signal: "notify::indent-char", callback: (owner: this, ...args: any) => void): number;
connect(signal: "notify::pretty", callback: (owner: this, ...args: any) => void): number;
connect(signal: "notify::root", callback: (owner: this, ...args: any) => void): number;
}
type GeneratorInitOptionsMixin = GObject.ObjectInitOptions &
Pick<IGenerator,
"indent" |
"indent_char" |
"pretty" |
"root">;
export interface GeneratorInitOptions extends GeneratorInitOptionsMixin {}
/** This construct is only for enabling class multi-inheritance,
* use {@link Generator} instead.
*/
type GeneratorMixin = IGenerator & GObject.Object;
/**
* `JsonGenerator` provides an object for generating a JSON data stream
* from a tree of [struct#Json.Node] instances, and put it into a buffer
* or a file.
*/
interface Generator extends GeneratorMixin {}
class Generator {
public constructor(options?: Partial<GeneratorInitOptions>);
/**
* Creates a new `JsonGenerator`.
*
* You can use this object to generate a JSON data stream starting from a
* data object model composed by [struct#Json.Node]s.
* @returns the newly created generator instance
*/
public static new(): Generator;
}
/** This construct is only for enabling class multi-inheritance,
* use {@link Parser} instead.
*/
interface IParser {
/**
* Whether the tree built by the parser should be immutable
* when created.
*
* Making the output immutable on creation avoids the expense
* of traversing it to make it immutable later.
*/
immutable: boolean;
/**
* Retrieves the line currently parsed, starting from 1.
*
* This function has defined behaviour only while parsing; calling this
* function from outside the signal handlers emitted by the parser will
* yield 0.
* @returns the currently parsed line, or 0.
*/
get_current_line(): number;
/**
* Retrieves the current position inside the current line, starting
* from 0.
*
* This function has defined behaviour only while parsing; calling this
* function from outside the signal handlers emitted by the parser will
* yield 0.
* @returns the position in the current line, or 0.
*/
get_current_pos(): number;
/**
* Retrieves the top level node from the parsed JSON stream.
*
* If the parser input was an empty string, or if parsing failed, the root
* will be `NULL`. It will also be `NULL` if it has been stolen using
* [method#Json.Parser.steal_root].
* @returns the root node.
*/
get_root(): Node | null;
/**
* A JSON data stream might sometimes contain an assignment, like:
*
* ```
* var _json_data = { "member_name" : [ ...
* ```
*
* even though it would technically constitute a violation of the RFC.
*
* `JsonParser` will ignore the left hand identifier and parse the right
* hand value of the assignment. `JsonParser` will record, though, the
* existence of the assignment in the data stream and the variable name
* used.
* @returns `TRUE` if there was an assignment, and `FALSE` otherwise
*
* the variable name
*/
has_assignment(): [ boolean, string | null ];
/**
* Loads a JSON stream from a buffer and parses it.
*
* You can call this function multiple times with the same parser, but the
* contents of the parser will be destroyed each time.
* @param data the buffer to parse
* @param length the length of the buffer, or -1 if it is `NUL` terminated
* @returns `TRUE` if the buffer was succesfully parsed
*/
load_from_data(data: string, length: number): boolean;
/**
* Loads a JSON stream from the content of `filename` and parses it.
*
* If the file is large or shared between processes,
* [method#Json.Parser.load_from_mapped_file] may be a more efficient
* way to load it.
*
* See also: [method#Json.Parser.load_from_data]
* @param filename the path for the file to parse
* @returns `TRUE` if the file was successfully loaded and parsed.
*/
load_from_file(filename: string): boolean;
/**
* Loads a JSON stream from the content of `filename` and parses it.
*
* Unlike [method#Json.Parser.load_from_file], `filename` will be memory
* mapped as read-only and parsed. `filename` will be unmapped before this
* function returns.
*
* If mapping or reading the file fails, a `G_FILE_ERROR` will be returned.
* @param filename the path for the file to parse
* @returns `TRUE` if the file was successfully loaded and parsed.
*/
load_from_mapped_file(filename: string): boolean;
/**
* Loads the contents of an input stream and parses them.
*
* If `cancellable` is not `NULL`, then the operation can be cancelled by
* triggering the cancellable object from another thread. If the
* operation was cancelled, `G_IO_ERROR_CANCELLED` will be set
* on the given `error`.
* @param stream the input stream with the JSON data
* @param cancellable a #GCancellable
* @returns `TRUE` if the data stream was successfully read and
* parsed, and `FALSE` otherwise
*/
load_from_stream(stream: Gio.InputStream, cancellable?: Gio.Cancellable | null): boolean;
/**
* Asynchronously reads the contents of a stream.
*
* For more details, see [method#Json.Parser.load_from_stream], which is the
* synchronous version of this call.
*
* When the operation is finished, #callback will be called. You should
* then call [method#Json.Parser.load_from_stream_finish] to get the result
* of the operation.
* @param stream the input stream with the JSON data
* @param cancellable a #GCancellable
* @param callback the function to call when the request is satisfied
*/
load_from_stream_async(stream: Gio.InputStream, cancellable?: Gio.Cancellable | null, callback?: Gio.AsyncReadyCallback | null): void;
/**
* Finishes an asynchronous stream loading started with
* [method#Json.Parser.load_from_stream_async].
* @param result the result of the asynchronous operation
* @returns `TRUE` if the content of the stream was successfully retrieved
* and parsed, and `FALSE` otherwise
*/
load_from_stream_finish(result: Gio.AsyncResult): boolean;
/**
* Steals the top level node from the parsed JSON stream.
*
* This will be `NULL` in the same situations as [method#Json.Parser.get_root]
* return `NULL`.
* @returns the root node
*/
steal_root(): Node | null;
/**
* The `::array-element` signal is emitted each time a parser
* has successfully parsed a single element of a JSON array.
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
* - array: a JSON array
* - index_: the index of the newly parsed array element
*
* @returns Callback ID
*/
connect(signal: "array-element", callback: (owner: this, array: Array, index_: number) => void): number;
/**
* The `::array-end` signal is emitted each time a parser
* has successfully parsed an entire JSON array.
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
* - array: the parsed JSON array
*
* @returns Callback ID
*/
connect(signal: "array-end", callback: (owner: this, array: Array) => void): number;
/**
* The `::array-start` signal is emitted each time a parser
* starts parsing a JSON array.
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
*
* @returns Callback ID
*/
connect(signal: "array-start", callback: (owner: this) => void): number;
/**
* The `::error` signal is emitted each time a parser encounters
* an error in a JSON stream.
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
* - error: the error
*
* @returns Callback ID
*/
connect(signal: "error", callback: (owner: this, error: any | null) => void): number;
/**
* The `::object-end` signal is emitted each time a parser
* has successfully parsed an entire JSON object.
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
* - object: the parsed JSON object
*
* @returns Callback ID
*/
connect(signal: "object-end", callback: (owner: this, object: Object) => void): number;
/**
* The `::object-member` signal is emitted each time a parser
* has successfully parsed a single member of a JSON object
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
* - object: the JSON object being parsed
* - member_name: the name of the newly parsed member
*
* @returns Callback ID
*/
connect(signal: "object-member", callback: (owner: this, object: Object, member_name: string) => void): number;
/**
* This signal is emitted each time a parser starts parsing a JSON object.
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
*
* @returns Callback ID
*/
connect(signal: "object-start", callback: (owner: this) => void): number;
/**
* This signal is emitted when a parser successfully finished parsing a
* JSON data stream
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
*
* @returns Callback ID
*/
connect(signal: "parse-end", callback: (owner: this) => void): number;
/**
* This signal is emitted when a parser starts parsing a JSON data stream.
* @param signal
* @param callback Callback function
* - owner: owner of the emitted event
*
* @returns Callback ID
*/
connect(signal: "parse-start", callback: (owner: this) => void): number;
connect(signal: "notify::immutable", callback: (owner: this, ...args: any) => void): number;
}
type ParserInitOptionsMixin = GObject.ObjectInitOptions &
Pick<IParser,
"immutable">;
export interface ParserInitOptions extends ParserInitOptionsMixin {}
/** This construct is only for enabling class multi-inheritance,
* use {@link Parser} instead.
*/
type ParserMixin = IParser & GObject.Object;
/**
* `JsonParser` provides an object for parsing a JSON data stream, either
* inside a file or inside a static buffer.
*
* ## Using `JsonParser`
*
* The `JsonParser` API is fairly simple:
*
* ```c
* gboolean
* parse_json (const char *filename)
* {
* g_autoptr(JsonParser) parser = json_parser_new ();
* g_autoptr(GError) error = NULL
*
* json_parser_load_from_file (parser, filename, &error);
* if (error != NULL)
* {
* g_critical ("Unable to parse '%s': %s", filename, error->message);
* return FALSE;
* }
*
* g_autoptr(JsonNode) root = json_parser_get_root (parser);
*
* // manipulate the object tree from the root node
*
* return TRUE
* }
* ```
*
* By default, the entire process of loading the data and parsing it is
* synchronous; the {@link [method#Json.Parser.load.from_stream_async}] API will
* load the data asynchronously, but parse it in the main context as the
* signals of the parser must be emitted in the same thread. If you do
* not use signals, and you wish to also parse the JSON data without blocking,
* you should use a `GTask` and the synchronous `JsonParser` API inside the
* task itself.
*/
interface Parser extends ParserMixin {}
class Parser {
public constructor(options?: Partial<ParserInitOptions>);
/**
* Creates a new JSON parser.
*
* You can use the `JsonParser` to load a JSON stream from either a file or a
* buffer and then walk the hierarchy using the data types API.
* @returns the newly created parser
*/
public static new(): Parser;
/**
* Creates a new parser instance with its [property#Json.Parser:immutable]
* property set to `TRUE` to create immutable output trees.
* @returns the newly created parser
*/
public static new_immutable(): Parser;
}
/** This construct is only for enabling class multi-inheritance,
* use {@link Path} instead.
*/
interface IPath {
/**
* Validates and decomposes the given expression.
*
* A JSONPath expression must be compiled before calling
* [method#Json.Path.match].
* @param expression a JSONPath expression
* @returns `TRUE` if the compilation was successful, and `FALSE`
* otherwise
*/
compile(expression: string): boolean;
/**
* Matches the JSON tree pointed by `root` using the expression compiled
* into the `JsonPath`.
*
* The nodes matching the expression will be copied into an array.
* @param root the root node of the JSON data to match
* @returns a newly-created node of type
* `JSON_NODE_ARRAY` containing the array of matching nodes
*/
match(root: Node): Node;
}
type PathInitOptionsMixin = GObject.ObjectInitOptions
export interface PathInitOptions extends PathInitOptionsMixin {}
/** This construct is only for enabling class multi-inheritance,
* use {@link Path} instead.
*/
type PathMixin = IPath & GObject.Object;
/**
* `JsonPath` is a simple class implementing the JSONPath syntax for extracting
* data out of a JSON tree.
*
* While the semantics of the JSONPath expressions are heavily borrowed by the
* XPath specification for XML, the syntax follows the ECMAScript origins of
* JSON.
*
* Once a `JsonPath` instance has been created, it has to compile a JSONPath
* expression using [method#Json.Path.compile] before being able to match it to
* a JSON tree; the same `JsonPath` instance can be used to match multiple JSON
* trees. It it also possible to compile a new JSONPath expression using the
* same `JsonPath` instance; the previous expression will be discarded only if
* the compilation of the new expression is successful.
*
* The simple convenience function [func#Json.Path.query] can be used for
* one-off matching.
*
* ## Syntax of the JSONPath expressions
*
* A JSONPath expression is composed by path indices and operators.
* Each path index can either be a member name or an element index inside
* a JSON tree. A JSONPath expression must start with the `$` operator; each
* path index is separated using either the dot notation or the bracket
* notation, e.g.:
*
* ```
* // dot notation
* $.store.book[0].title
*
* // bracket notation
* $['store']['book'][0]['title']
* ```
*
* The available operators are:
*
* * The `$` character represents the root node of the JSON tree, and
* matches the entire document.
*
* * Child nodes can either be matched using `.` or `[]`. For instance,
* both `$.store.book` and `$['store']['book']` match the contents of
* the book member of the store object.
*
* * Child nodes can be reached without specifying the whole tree structure
* through the recursive descent operator, or `..`. For instance,
* `$..author` matches all author member in every object.
*
* * Child nodes can grouped through the wildcard operator, or `*`. For
* instance, `$.store.book[*].author` matches all author members of any
* object element contained in the book array of the store object.
*
* * Element nodes can be accessed using their index (starting from zero)
* in the subscript operator `[]`. For instance, `$.store.book[0]` matches
* the first element of the book array of the store object.
*
* * Subsets of element nodes can be accessed using the set notation
* operator `[i,j,...]`. For instance, `$.store.book[0,2]` matches the
* elements 0 and 2 (the first and third) of the book array of the store
* object.
*
* * Slices of element nodes can be accessed using the slice notation
* operation `[start:end:step]`. If start is omitted, the starting index
* of the slice is implied to be zero; if end is omitted, the ending index
* of the slice is implied to be the length of the array; if step is
* omitted, the step of the slice is implied to be 1. For instance,
* `$.store.book[:2]` matches the first two elements of the book array
* of the store object.
*
* More information about JSONPath is available on Stefan Gössner's
* [JSONPath website](http://goessner.net/articles/JsonPath/).
*
* ## Example of JSONPath matches
*
* The following example shows some of the results of using `JsonPath`
* on a JSON tree. We use the following JSON description of a bookstore:
*
* ```json
* { "store": {
* "book": [
* { "category": "reference", "author": "Nigel Rees",
* "title": "Sayings of the Century", "price": "8.95" },
* { "category": "fiction", "author": "Evelyn Waugh",
* "title": "Sword of Honour", "price": "12.99" },
* { "category": "fiction", "author": "Herman Melville",
* "title": "Moby Dick", "isbn": "0-553-21311-3",
* "price": "8.99" },
* { "category": "fiction", "author": "J. R. R. Tolkien",
* "title": "The Lord of the Rings", "isbn": "0-395-19395-8",
* "price": "22.99" }
* ],
* "bicycle": { "color": "red", "price": "19.95" }
* }
* }
* ```
*
* We can parse the JSON using [class#Json.Parser]:
*
* ```c
* JsonParser *parser = json_parser_new ();
* json_parser_load_from_data (parser, json_data, -1, NULL);
* ```
*
* If we run the following code:
*
* ```c
* JsonNode *result;
* JsonPath *path = json_path_new ();
* json_path_compile (path, "$.store..author", NULL);
* result = json_path_match (path, json_parser_get_root (parser));
* ```
*
* The `result` node will contain an array with all values of the
* author member of the objects in the JSON tree. If we use a
* [class#Json.Generator] to convert the `result` node to a string
* and print it:
*
* ```c
* JsonGenerator *generator = json_generator_new ();
* json_generator_set_root (generator, result);
* char *str = json_generator_to_data (generator, NULL);
* g_print ("Results: %s\n", str);
* ```
*
* The output will be:
*
* ```json
* ["Nigel Rees","Evelyn Waugh","Herman Melville","J. R. R. Tolkien"]
* ```
*/
interface Path extends PathMixin {}
class Path {
public constructor(options?: Partial<PathInitOptions>);
/**
* Creates a new `JsonPath` instance.
*
* Once created, the `JsonPath` object should be used with
* [method#Json.Path.compile] and [method#Json.Path.match].
* @returns the newly created path
*/
public static new(): Path;
/**
* Queries a JSON tree using a JSONPath expression.
*
* This function is a simple wrapper around [ctor#Json.Path.new],
* [method#Json.Path.compile], and [method#Json.Path.match]. It implicitly
* creates a `JsonPath` instance, compiles the given expression and matches
* it against the JSON tree pointed by `root`.
* @param expression a JSONPath expression
* @param root the root of a JSON tree
* @returns a newly-created node of type
* `JSON_NODE_ARRAY` containing the array of matching nodes
*/
public static query(expression: string, root: Node): Node;
}
/** This construct is only for enabling class multi-inheritance,
* use {@link Reader} instead.
*/
interface IReader {
/**
* The root of the JSON tree that the reader should read.
*/
root: Node;
/**
* Counts the elements of the current position, if the reader is
* positioned on an array.
*
* In case of failure, the reader is set to an error state.
* @returns the number of elements, or -1.
*/
count_elements(): number;
/**
* Counts the members of the current position, if the reader is
* positioned on an object.
*
* In case of failure, the reader is set to an error state.
* @returns the number of members, or -1
*/
count_members(): number;
/**
* Moves the cursor back to the previous node after being positioned
* inside an array.
*
* This function resets the error state of the reader, if any was set.
*/
end_element(): void;
/**
* Moves the cursor back to the previous node after being positioned
* inside an object.
*
* This function resets the error state of the reader, if any was set.
*/
end_member(): void;
/**
* Retrieves the boolean value of the current position of the reader.
*
* See also: [method#Json.Reader.get_value]
* @returns the boolean value
*/
get_boolean_value(): boolean;
/**
* Retrieves the reader node at the current position.
* @returns the current node of the reader
*/
get_current_node(): Node | null;
/**
* Retrieves the floating point value of the current position of the reader.
*
* See also: [method#Json.Reader.get_value]
* @returns the floating point value
*/
get_double_value(): number;
/**
* Retrieves the error currently set on the reader.
* @returns the current error
*/
get_error(): GLib.Error | null;
/**
* Retrieves the integer value of the current position of the reader.
*
* See also: [method#Json.Reader.get_value]
* @returns the integer value
*/
get_int_value(): number;
/**
* Retrieves the name of the current member.
*
* In case of failure, the reader is set to an error state.
* @returns the name of the member
*/
get_member_name(): string | null;
/**
* Checks whether the value of the current position of the reader is `null`.
*
* See also: [method#Json.Reader.get_value]
* @returns `TRUE` if `null` is set, and `FALSE` otherwise
*/
get_null_value(): boolean;
/**
* Retrieves the string value of the current position of the reader.
*
* See also: [method#Json.Reader.get_value]
* @returns the string value
*/
get_string_value(): string;
/**
* Retrieves the value node at the current position of the reader.
*
* If the current position does not contain a scalar value, the reader
* is set to an error state.
* @returns the current value node
*/
get_value(): Node | null;
/**
* Checks whether the reader is currently on an array.
* @returns `TRUE` if the reader is on an array
*/
is_array(): boolean;
/**
* Checks whether the reader is currently on an object.
* @returns `TRUE` if the reader is on an object
*/
is_object(): boolean;
/**
* Checks whether the reader is currently on a value.
* @returns `TRUE` if the reader is on a value
*/
is_value(): boolean;
/**
* Retrieves a list of member names from the current position, if the reader
* is positioned on an object.
*
* In case of failure, the reader is set to an error state.
* @returns the members of
* the object
*/
list_members(): string[];
/**
* Advances the cursor of the reader to the element of the array or
* the member of the object at the given position.
*
* You can use [method#Json.Reader.get_value] and its wrapper functions to
* retrieve the value of the element; for instance, the following code will
* read the first element of the array at the current cursor position:
*
* ```c
* json_reader_read_element (reader, 0);
* int_value = json_reader_get_int_value (reader);