e621stream 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +35 -0
  4. data/lib/e621stream/client/options.rb +20 -0
  5. data/lib/e621stream/client.rb +211 -0
  6. data/lib/e621stream/close_codes.rb +23 -0
  7. data/lib/e621stream/event.rb +24 -0
  8. data/lib/e621stream/events.rb +29 -0
  9. data/lib/e621stream/stream_error.rb +18 -0
  10. data/lib/e621stream/version.rb +5 -0
  11. data/lib/e621stream.rb +18 -0
  12. data/sorbet/config +6 -0
  13. data/sorbet/rbi/annotations/.gitattributes +1 -0
  14. data/sorbet/rbi/annotations/minitest.rbi +120 -0
  15. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  16. data/sorbet/rbi/gems/.gitattributes +1 -0
  17. data/sorbet/rbi/gems/ast@2.4.3.rbi +550 -0
  18. data/sorbet/rbi/gems/async-http@0.105.0.rbi +1649 -0
  19. data/sorbet/rbi/gems/async-pool@0.12.0.rbi +219 -0
  20. data/sorbet/rbi/gems/async-websocket@0.30.2.rbi +271 -0
  21. data/sorbet/rbi/gems/async@2.46.0.rbi +2193 -0
  22. data/sorbet/rbi/gems/benchmark@0.5.0.rbi +495 -0
  23. data/sorbet/rbi/gems/console@1.38.0.rbi +1552 -0
  24. data/sorbet/rbi/gems/erb@6.0.7.rbi +1581 -0
  25. data/sorbet/rbi/gems/erubi@1.13.1.rbi +153 -0
  26. data/sorbet/rbi/gems/fiber-annotation@0.2.0.rbi +62 -0
  27. data/sorbet/rbi/gems/fiber-local@1.1.0.rbi +36 -0
  28. data/sorbet/rbi/gems/fiber-storage@1.0.1.rbi +43 -0
  29. data/sorbet/rbi/gems/io-console@0.9.5.rbi +9 -0
  30. data/sorbet/rbi/gems/io-endpoint@0.19.0.rbi +1079 -0
  31. data/sorbet/rbi/gems/io-event@1.22.3.rbi +971 -0
  32. data/sorbet/rbi/gems/io-stream@0.14.0.rbi +805 -0
  33. data/sorbet/rbi/gems/json@3.1.0.rbi +1929 -0
  34. data/sorbet/rbi/gems/language_server-protocol@3.17.0.6.rbi +9 -0
  35. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +189 -0
  36. data/sorbet/rbi/gems/logger@1.7.0.rbi +896 -0
  37. data/sorbet/rbi/gems/minitest@5.27.0.rbi +1499 -0
  38. data/sorbet/rbi/gems/netrc@0.11.0.rbi +147 -0
  39. data/sorbet/rbi/gems/openssl@4.0.2.rbi +4366 -0
  40. data/sorbet/rbi/gems/parallel@2.3.0.rbi +332 -0
  41. data/sorbet/rbi/gems/parser@3.3.13.0.rbi +5146 -0
  42. data/sorbet/rbi/gems/pp@0.6.4.rbi +373 -0
  43. data/sorbet/rbi/gems/prettyprint@0.2.1.rbi +476 -0
  44. data/sorbet/rbi/gems/prism@1.9.0.rbi +42213 -0
  45. data/sorbet/rbi/gems/protocol-hpack@1.5.1.rbi +418 -0
  46. data/sorbet/rbi/gems/protocol-http1@0.41.1.rbi +894 -0
  47. data/sorbet/rbi/gems/protocol-http2@0.29.2.rbi +2277 -0
  48. data/sorbet/rbi/gems/protocol-http@0.72.1.rbi +3801 -0
  49. data/sorbet/rbi/gems/protocol-rack@0.23.0.rbi +9 -0
  50. data/sorbet/rbi/gems/protocol-url@0.19.0.rbi +9 -0
  51. data/sorbet/rbi/gems/protocol-websocket@0.21.3.rbi +1087 -0
  52. data/sorbet/rbi/gems/racc@1.8.1.rbi +169 -0
  53. data/sorbet/rbi/gems/rack@3.2.8.rbi +9 -0
  54. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +362 -0
  55. data/sorbet/rbi/gems/rake@13.4.2.rbi +3127 -0
  56. data/sorbet/rbi/gems/rbi@0.5.0.rbi +5875 -0
  57. data/sorbet/rbi/gems/rbs@4.2.0.rbi +7133 -0
  58. data/sorbet/rbi/gems/rdoc@8.1.0.rbi +9 -0
  59. data/sorbet/rbi/gems/regexp_parser@2.13.1.rbi +3500 -0
  60. data/sorbet/rbi/gems/reline@0.7.0.rbi +2449 -0
  61. data/sorbet/rbi/gems/require-hooks@0.5.1.rbi +152 -0
  62. data/sorbet/rbi/gems/rexml@3.4.4.rbi +4905 -0
  63. data/sorbet/rbi/gems/rubocop-ast@1.51.0.rbi +7230 -0
  64. data/sorbet/rbi/gems/rubocop-rake@0.7.1.rbi +314 -0
  65. data/sorbet/rbi/gems/rubocop@1.92.2.rbi +69094 -0
  66. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +988 -0
  67. data/sorbet/rbi/gems/rubydex@0.4.4.rbi +1620 -0
  68. data/sorbet/rbi/gems/spoom@1.8.13.rbi +7380 -0
  69. data/sorbet/rbi/gems/tapioca@0.20.0.rbi +3752 -0
  70. data/sorbet/rbi/gems/thor@1.5.0.rbi +3870 -0
  71. data/sorbet/rbi/gems/tsort@0.2.0.rbi +389 -0
  72. data/sorbet/rbi/gems/unicode-display_width@3.3.0.rbi +130 -0
  73. data/sorbet/rbi/gems/unicode-emoji@4.3.0.rbi +254 -0
  74. data/sorbet/rbi/gems/zeitwerk@2.8.3.rbi +1178 -0
  75. data/sorbet/tapioca/config.yml +13 -0
  76. data/sorbet/tapioca/require.rb +4 -0
  77. metadata +175 -0
@@ -0,0 +1,1929 @@
1
+ # typed: false
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `json` gem.
5
+ # Please instead update this file by running `bin/tapioca gem json`.
6
+
7
+
8
+ # = JavaScript \Object Notation (\JSON)
9
+ #
10
+ # \JSON is a lightweight data-interchange format.
11
+ #
12
+ # \JSON is easy for us humans to read and write,
13
+ # and equally simple for machines to read (parse) and write (generate).
14
+ #
15
+ # \JSON is language-independent, making it an ideal interchange format
16
+ # for applications in differing programming languages
17
+ # and on differing operating systems.
18
+ #
19
+ # == \JSON Values
20
+ #
21
+ # A \JSON value is one of the following:
22
+ # - Double-quoted text: <tt>"foo"</tt>.
23
+ # - Number: +1+, +1.0+, +2.0e2+.
24
+ # - Boolean: +true+, +false+.
25
+ # - Null: +null+.
26
+ # - \Array: an ordered list of values, enclosed by square brackets:
27
+ # ["foo", 1, 1.0, 2.0e2, true, false, null]
28
+ #
29
+ # - \Object: a collection of name/value pairs, enclosed by curly braces;
30
+ # each name is double-quoted text;
31
+ # the values may be any \JSON values:
32
+ # {"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}
33
+ #
34
+ # A \JSON array or object may contain nested arrays, objects, and scalars
35
+ # to any depth:
36
+ # {"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}
37
+ # [{"foo": 0, "bar": 1}, ["baz", 2]]
38
+ #
39
+ # == Using \Module \JSON
40
+ #
41
+ # To make module \JSON available in your code, begin with:
42
+ # require 'json'
43
+ #
44
+ # All examples here assume that this has been done.
45
+ #
46
+ # === Parsing \JSON
47
+ #
48
+ # You can parse a \String containing \JSON data using
49
+ # either of two methods:
50
+ # - <tt>JSON.parse(source, **opts)</tt>
51
+ # - <tt>JSON.parse!(source, **opts)</tt>
52
+ #
53
+ # where
54
+ # - +source+ is a Ruby object.
55
+ # - +opts+ are keyword arguments that control both input
56
+ # allowed and output formatting.
57
+ #
58
+ # The difference between the two methods
59
+ # is that JSON.parse! omits some checks
60
+ # and may not be safe for some +source+ data;
61
+ # use it only for data from trusted sources.
62
+ # Use the safer method JSON.parse for less trusted sources.
63
+ #
64
+ # ==== Parsing \JSON Arrays
65
+ #
66
+ # When +source+ is a \JSON array, JSON.parse by default returns a Ruby \Array:
67
+ # json = '["foo", 1, 1.0, 2.0e2, true, false, null]'
68
+ # ruby = JSON.parse(json)
69
+ # ruby # => ["foo", 1, 1.0, 200.0, true, false, nil]
70
+ # ruby.class # => Array
71
+ #
72
+ # The \JSON array may contain nested arrays, objects, and scalars
73
+ # to any depth:
74
+ # json = '[{"foo": 0, "bar": 1}, ["baz", 2]]'
75
+ # JSON.parse(json) # => [{"foo"=>0, "bar"=>1}, ["baz", 2]]
76
+ #
77
+ # ==== Parsing \JSON \Objects
78
+ #
79
+ # When the source is a \JSON object, JSON.parse by default returns a Ruby \Hash:
80
+ # json = '{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}'
81
+ # ruby = JSON.parse(json)
82
+ # ruby # => {"a"=>"foo", "b"=>1, "c"=>1.0, "d"=>200.0, "e"=>true, "f"=>false, "g"=>nil}
83
+ # ruby.class # => Hash
84
+ #
85
+ # The \JSON object may contain nested arrays, objects, and scalars
86
+ # to any depth:
87
+ # json = '{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}'
88
+ # JSON.parse(json) # => {"foo"=>{"bar"=>1, "baz"=>2}, "bat"=>[0, 1, 2]}
89
+ #
90
+ # ==== Parsing \JSON Scalars
91
+ #
92
+ # When the source is a \JSON scalar (not an array or object),
93
+ # JSON.parse returns a Ruby scalar.
94
+ #
95
+ # \String:
96
+ # ruby = JSON.parse('"foo"')
97
+ # ruby # => 'foo'
98
+ # ruby.class # => String
99
+ # \Integer:
100
+ # ruby = JSON.parse('1')
101
+ # ruby # => 1
102
+ # ruby.class # => Integer
103
+ # \Float:
104
+ # ruby = JSON.parse('1.0')
105
+ # ruby # => 1.0
106
+ # ruby.class # => Float
107
+ # ruby = JSON.parse('2.0e2')
108
+ # ruby # => 200.0
109
+ # ruby.class # => Float
110
+ # Boolean:
111
+ # ruby = JSON.parse('true')
112
+ # ruby # => true
113
+ # ruby.class # => TrueClass
114
+ # ruby = JSON.parse('false')
115
+ # ruby # => false
116
+ # ruby.class # => FalseClass
117
+ # Null:
118
+ # ruby = JSON.parse('null')
119
+ # ruby # => nil
120
+ # ruby.class # => NilClass
121
+ #
122
+ # ==== Parsing Options
123
+ #
124
+ # ====== Input Options
125
+ #
126
+ # Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed;
127
+ # defaults to +100+;
128
+ # You can set it to +false+ to disable depth checking entirely, but that is dangerous
129
+ # when parsing untrusted input.
130
+ #
131
+ # With the default, +100+:
132
+ # source = '[0, [1, [2, [3]]]]'
133
+ # ruby = JSON.parse(source)
134
+ # ruby # => [0, [1, [2, [3]]]]
135
+ # Too deep:
136
+ # # Raises JSON::NestingError (nesting of 2 is too deep):
137
+ # JSON.parse(source, max_nesting: 1)
138
+ # Bad value:
139
+ # # Raises TypeError (no implicit conversion of Symbol into Integer):
140
+ # JSON.parse(source, max_nesting: :foo)
141
+ #
142
+ # ---
143
+ #
144
+ # Option +allow_duplicate_key+ specifies whether duplicate keys in objects
145
+ # should be ignored or cause an error to be raised:
146
+ #
147
+ # When set to +false+, the default:
148
+ # JSON.parse('{"a": 1, "a": 2}') # duplicate key "a" at line 1 column 1 (JSON::ParserError)
149
+ #
150
+ # When set to +true+:
151
+ # # The last value is used.
152
+ # JSON.parse('{"a": 1, "a": 2}', allow_duplicate_key: true) # => {"a" => 2}
153
+ #
154
+ # ---
155
+ #
156
+ # Option +allow_nan+ (boolean) specifies whether to allow
157
+ # NaN, Infinity, and MinusInfinity in +source+;
158
+ # defaults to +false+.
159
+ #
160
+ # With the default, +false+:
161
+ # # Raises JSON::ParserError (unexpected token 'NaN]' at line 1 column 2):
162
+ # JSON.parse('[NaN]')
163
+ # # Raises JSON::ParserError (unexpected token 'Infinity]' at line 1 column 2):
164
+ # JSON.parse('[Infinity]')
165
+ # # Raises JSON::ParserError (invalid number: '-Infinity]' at line 1 column 2):
166
+ # JSON.parse('[-Infinity]')
167
+ # Allow:
168
+ # source = '[NaN, Infinity, -Infinity]'
169
+ # ruby = JSON.parse(source, allow_nan: true)
170
+ # ruby # => [NaN, Infinity, -Infinity]
171
+ #
172
+ # ---
173
+ #
174
+ # Option +allow_trailing_comma+ (boolean) specifies whether to allow
175
+ # trailing commas in objects and arrays;
176
+ # defaults to +false+.
177
+ #
178
+ # With the default, +false+:
179
+ # JSON.parse('[1,]') # unexpected character: ']' at line 1 column 4 (JSON::ParserError)
180
+ #
181
+ # When enabled:
182
+ # JSON.parse('[1,]', allow_trailing_comma: true) # => [1]
183
+ #
184
+ # ---
185
+ #
186
+ # Option +allow_comments+ (boolean) specifies whether to allow
187
+ # JavaScript style comments (either <tt>// comment</tt> or <tt>/* comment */</tt>);
188
+ # defaults to +false+.
189
+ #
190
+ # When set to +false+, the default:
191
+ # JSON.parse('/* comment */ {"a": 1, "a": 2}') # unexpected token '/*' at line 1 column 1 (JSON::ParserError)
192
+ #
193
+ # When set to +true+, comments are ignored:
194
+ # JSON.parse('/* comment */ {"a": 1} // more comment', allow_comments: true) # => {"a" => 1}
195
+ #
196
+ # ---
197
+ #
198
+ # Option +allow_control_characters+ (boolean) specifies whether to allow
199
+ # unescaped ASCII control characters, such as newlines, in strings;
200
+ # defaults to +false+.
201
+ #
202
+ # With the default, +false+:
203
+ # JSON.parse(%{"Hello\nWorld"}) # invalid ASCII control character in string: \nWorld" at line 2 column 0 (JSON::ParserError)
204
+ #
205
+ # When enabled:
206
+ # JSON.parse(%{"Hello\nWorld"}, allow_control_characters: true) # => "Hello\nWorld"
207
+ #
208
+ # ---
209
+ #
210
+ # Option +allow_invalid_escape+ (boolean) specifies whether to ignore backslahes that are followed
211
+ # by an invalid escape character in strings;
212
+ # defaults to +false+.
213
+ #
214
+ # With the default, +false+:
215
+ # JSON.parse('"Hell\o"') # invalid escape character in string: '\o"' at line 1 column 6 (JSON::ParserError)
216
+ #
217
+ # When enabled:
218
+ # JSON.parse('"Hell\o"', allow_invalid_escape: true) # => "Hello"
219
+ #
220
+ # ====== Output Options
221
+ #
222
+ # Option +freeze+ (boolean) specifies whether the returned objects will be frozen;
223
+ # defaults to +false+.
224
+ #
225
+ # Option +symbolize_names+ (boolean) specifies whether returned \Hash keys
226
+ # should be Symbols;
227
+ # defaults to +false+ (use Strings).
228
+ #
229
+ # With the default, +false+:
230
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
231
+ # ruby = JSON.parse(source)
232
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
233
+ # Use Symbols:
234
+ # ruby = JSON.parse(source, symbolize_names: true)
235
+ # ruby # => {a: "foo", b: 1.0, c: true, d: false, e: nil}
236
+ #
237
+ # ---
238
+ #
239
+ # Option +object_class+ (\Class) specifies the Ruby class to be used
240
+ # for each \JSON object;
241
+ # defaults to \Hash.
242
+ #
243
+ # With the default, \Hash:
244
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
245
+ # ruby = JSON.parse(source)
246
+ # ruby.class # => Hash
247
+ # Use class \OpenStruct:
248
+ # ruby = JSON.parse(source, object_class: OpenStruct)
249
+ # ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
250
+ #
251
+ # ---
252
+ #
253
+ # Option +array_class+ (\Class) specifies the Ruby class to be used
254
+ # for each \JSON array;
255
+ # defaults to \Array.
256
+ #
257
+ # With the default, \Array:
258
+ # source = '["foo", 1.0, true, false, null]'
259
+ # ruby = JSON.parse(source)
260
+ # ruby.class # => Array
261
+ # Use class \Set:
262
+ # ruby = JSON.parse(source, array_class: Set)
263
+ # ruby # => Set["foo", 1.0, true, false, nil]
264
+ #
265
+ # === Generating \JSON
266
+ #
267
+ # To generate a Ruby \String containing \JSON data,
268
+ # use method <tt>JSON.generate(source, opts)</tt>, where
269
+ # - +source+ is a Ruby object.
270
+ # - +opts+ is a \Hash object containing options
271
+ # that control both input allowed and output formatting.
272
+ #
273
+ # ==== Generating \JSON from Arrays
274
+ #
275
+ # When the source is a Ruby \Array, JSON.generate returns
276
+ # a \String containing a \JSON array:
277
+ # ruby = [0, 's', :foo]
278
+ # json = JSON.generate(ruby)
279
+ # json # => '[0,"s","foo"]'
280
+ #
281
+ # The Ruby \Array array may contain nested arrays, hashes, and scalars
282
+ # to any depth:
283
+ # ruby = [0, [1, 2], {foo: 3, bar: 4}]
284
+ # json = JSON.generate(ruby)
285
+ # json # => '[0,[1,2],{"foo":3,"bar":4}]'
286
+ #
287
+ # ==== Generating \JSON from Hashes
288
+ #
289
+ # When the source is a Ruby \Hash, JSON.generate returns
290
+ # a \String containing a \JSON object:
291
+ # ruby = {foo: 0, bar: 's', baz: :bat}
292
+ # json = JSON.generate(ruby)
293
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
294
+ #
295
+ # The Ruby \Hash array may contain nested arrays, hashes, and scalars
296
+ # to any depth:
297
+ # ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
298
+ # json = JSON.generate(ruby)
299
+ # json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
300
+ #
301
+ # ==== Generating \JSON from Other Objects
302
+ #
303
+ # When the source is neither an \Array nor a \Hash,
304
+ # the generated \JSON data depends on the class of the source.
305
+ #
306
+ # When the source is a Ruby \Integer or \Float, JSON.generate returns
307
+ # a \String containing a \JSON number:
308
+ # JSON.generate(42) # => '42'
309
+ # JSON.generate(0.42) # => '0.42'
310
+ #
311
+ # When the source is a Ruby \String, JSON.generate returns
312
+ # a \String containing a \JSON string (with double-quotes):
313
+ # JSON.generate('A string') # => '"A string"'
314
+ #
315
+ # When the source is +true+, +false+ or +nil+, JSON.generate returns
316
+ # a \String containing the corresponding \JSON token:
317
+ # JSON.generate(true) # => 'true'
318
+ # JSON.generate(false) # => 'false'
319
+ # JSON.generate(nil) # => 'null'
320
+ #
321
+ # When the source is none of the above, JSON.generate returns
322
+ # a \String containing a \JSON string representation of the source:
323
+ # JSON.generate(:foo) # => '"foo"'
324
+ # JSON.generate(Complex(0, 0)) # => '"0+0i"'
325
+ # JSON.generate(Dir.new('.')) # => '"#<Dir:0x...>"'
326
+ #
327
+ # ==== Generating Options
328
+ #
329
+ # ====== Input Options
330
+ #
331
+ # Option +allow_nan+ (boolean) specifies whether
332
+ # +NaN+, +Infinity+, and +-Infinity+ may be generated;
333
+ # defaults to +false+.
334
+ #
335
+ # With the default, +false+:
336
+ # # Raises JSON::GeneratorError (NaN not allowed in JSON):
337
+ # JSON.generate(JSON::NaN)
338
+ # # Raises JSON::GeneratorError (Infinity not allowed in JSON):
339
+ # JSON.generate(JSON::Infinity)
340
+ # # Raises JSON::GeneratorError (-Infinity not allowed in JSON):
341
+ # JSON.generate(JSON::MinusInfinity)
342
+ #
343
+ # Allow:
344
+ # ruby = [Float::NAN, Float::INFINITY, JSON::NaN, JSON::Infinity, JSON::MinusInfinity]
345
+ # JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,NaN,Infinity,-Infinity]'
346
+ #
347
+ # ---
348
+ #
349
+ # Option +allow_duplicate_key+ (boolean) specifies whether
350
+ # hashes with duplicate keys should be allowed or produce an error.
351
+ # Defaults to +false+, which raises an error.
352
+ #
353
+ # With the default, +false+:
354
+ # JSON.generate({foo: 1, "foo" => 2})
355
+ # # detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
356
+ #
357
+ # With +true+:
358
+ # JSON.generate({foo: 1, "foo" => 2}, allow_duplicate_key: true)
359
+ # # => '{"foo":1,"foo":2}'
360
+ #
361
+ # ---
362
+ #
363
+ # Option +max_nesting+ (\Integer) specifies the maximum nesting depth
364
+ # in +obj+; defaults to +100+.
365
+ #
366
+ # With the default, +100+:
367
+ # obj = [[[[[[0]]]]]]
368
+ # JSON.generate(obj) # => '[[[[[[0]]]]]]'
369
+ #
370
+ # Too deep:
371
+ # # Raises JSON::NestingError (nesting of 2 is too deep. Did you try to serialize objects with circular references?):
372
+ # JSON.generate(obj, max_nesting: 2)
373
+ #
374
+ # With +false+:
375
+ # obj = []
376
+ # obj[0] = obj
377
+ # # Raises SystemStackError (stack level too deep):
378
+ # JSON.generate(obj, max_nesting: false)
379
+ #
380
+ # Setting +max_nesting+ to +false+ or a very large number can lead to a stack overflow
381
+ # which may leave the process in an unrecoverable state.
382
+ # It is highly discouraged.
383
+ #
384
+ # ====== Escaping Options
385
+ #
386
+ # Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
387
+ # and <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script
388
+ # tags.
389
+ #
390
+ # Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range
391
+ # should be escaped.
392
+ #
393
+ # ====== Output Options
394
+ #
395
+ # The default formatting options generate the most compact
396
+ # \JSON data, all on one line and with no whitespace.
397
+ #
398
+ # You can use these formatting options to generate
399
+ # \JSON data in a more open format, using whitespace.
400
+ # See also JSON.pretty_generate.
401
+ #
402
+ # - Option +array_nl+ (\String) specifies a string (usually a newline)
403
+ # to be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>.
404
+ # - Option +object_nl+ (\String) specifies a string (usually a newline)
405
+ # to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
406
+ # - Option +indent+ (\String) specifies the string (usually spaces) to be
407
+ # used for indentation; defaults to the empty \String, <tt>''</tt>;
408
+ # has no effect unless options +array_nl+ or +object_nl+ specify newlines.
409
+ # - Option +space+ (\String) specifies a string (usually a space) to be
410
+ # inserted after the colon in each \JSON object's pair;
411
+ # defaults to the empty \String, <tt>''</tt>.
412
+ # - Option +space_before+ (\String) specifies a string (usually a space) to be
413
+ # inserted before the colon in each \JSON object's pair;
414
+ # defaults to the empty \String, <tt>''</tt>.
415
+ # - Option +sort_keys+ (boolean or \Proc) controls whether and how the keys of a
416
+ # hash are sorted when generating the output; defaults to +false+.
417
+ # When +true+, keys are sorted lexicographically. When a \Proc, it receives
418
+ # the entire \Hash and must return a \Hash with its pairs in the desired
419
+ # order, allowing for arbitrary sort orders.
420
+ # - Option +rfc8785+ (boolean) controls whether the generated JSON will be canonicalized
421
+ # as defined in RFC8785.
422
+ # Integers are converted to Float before formatting and may be rounded.
423
+ # Integers outside the finite Float range raise JSON::GeneratorError.
424
+ # Nonempty +indent+, +space+, +space_before+, +object_nl+, or +array_nl+,
425
+ # and enabled +ascii_only+, +script_safe+, or +allow_nan+ raise ArgumentError.
426
+ # JSON.dump defaults +allow_nan+ to +false+ when +rfc8785+ is enabled.
427
+ # JSON::Fragment contents are inserted as is; the caller must ensure they are canonical.
428
+ #
429
+ # In this example, +obj+ is used first to generate the shortest
430
+ # \JSON data (no whitespace), then again with all formatting options
431
+ # specified:
432
+ #
433
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
434
+ # json = JSON.generate(obj)
435
+ # puts 'Compact:', json
436
+ # opts = {
437
+ # array_nl: "\n",
438
+ # object_nl: "\n",
439
+ # indent: ' ',
440
+ # space_before: ' ',
441
+ # space: ' '
442
+ # }
443
+ # puts 'Open:', JSON.generate(obj, opts)
444
+ #
445
+ # Output:
446
+ # Compact:
447
+ # {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
448
+ # Open:
449
+ # {
450
+ # "foo" : [
451
+ # "bar",
452
+ # "baz"
453
+ # ],
454
+ # "bat" : {
455
+ # "bam" : 0,
456
+ # "bad" : 1
457
+ # }
458
+ # }
459
+ #
460
+ # pkg:gem/json#lib/json/version.rb:3
461
+ module JSON
462
+ private
463
+
464
+ # :call-seq:
465
+ # JSON.dump(obj, io = nil, _deprecated_limit = nil, options = nil)
466
+ #
467
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
468
+ #
469
+ # - Argument +io+, if given, should respond to method +write+;
470
+ # the \JSON \String is written to +io+, and +io+ is returned.
471
+ # If +io+ is not given, the \JSON \String is returned.
472
+ # - Argument +_deprecated_limit+ is deprecated, pass the +:max_nesting+ option instead.
473
+ # ---
474
+ #
475
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
476
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
477
+ # json = JSON.dump(obj)
478
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
479
+ #
480
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
481
+ # path = 't.json'
482
+ # File.open(path, 'w') do |file|
483
+ # JSON.dump(obj, file)
484
+ # end # => #<File:t.json (closed)>
485
+ # puts File.read(path)
486
+ # Output:
487
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
488
+ #
489
+ # pkg:gem/json#lib/json/common.rb:747
490
+ def dump(obj, anIO = T.unsafe(nil), _deprecated_limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
491
+
492
+ # :call-seq:
493
+ # JSON.generate(obj, opts = nil) -> new_string
494
+ #
495
+ # Returns a \String containing the generated \JSON data.
496
+ #
497
+ # See also JSON.pretty_generate.
498
+ #
499
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
500
+ #
501
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
502
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
503
+ #
504
+ # ---
505
+ #
506
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
507
+ # obj = ["foo", 1.0, true, false, nil]
508
+ # json = JSON.generate(obj)
509
+ # json # => '["foo",1.0,true,false,null]'
510
+ #
511
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
512
+ # obj = {foo: 0, bar: 's', baz: :bat}
513
+ # json = JSON.generate(obj)
514
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
515
+ #
516
+ # For examples of generating from other Ruby objects, see
517
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
518
+ #
519
+ # ---
520
+ #
521
+ # Raises an exception if any formatting option is not a \String.
522
+ #
523
+ # Raises an exception if +obj+ contains circular references:
524
+ # a = []; b = []; a.push(b); b.push(a)
525
+ # # Raises JSON::NestingError (nesting of 100 is too deep. Did you try to serialize objects with circular references?):
526
+ # JSON.generate(a)
527
+ #
528
+ # pkg:gem/json#lib/json/common.rb:373
529
+ def generate(obj, opts = T.unsafe(nil)); end
530
+
531
+ # :call-seq:
532
+ # JSON.load(source, options = {}) -> object
533
+ # JSON.load(source, proc = nil, options = {}) -> object
534
+ #
535
+ # Returns the Ruby objects created by parsing the given +source+.
536
+ #
537
+ # - Argument +source+ must be, or be convertible to, a \String:
538
+ # - If +source+ responds to instance method +to_str+,
539
+ # <tt>source.to_str</tt> becomes the source.
540
+ # - If +source+ responds to instance method +to_io+,
541
+ # <tt>source.to_io.read</tt> becomes the source.
542
+ # - If +source+ responds to instance method +read+,
543
+ # <tt>source.read</tt> becomes the source.
544
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
545
+ # - Option +allow_blank+ specifies a truthy value.
546
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
547
+ # - Otherwise, +source+ remains the source.
548
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
549
+ # It will be called recursively with each result (depth-first order).
550
+ # See details below.
551
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
552
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
553
+ #
554
+ # ---
555
+ #
556
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
557
+ # <tt>parse(source, opts)</tt>; see #parse.
558
+ #
559
+ # Source for following examples:
560
+ # source = <<~JSON
561
+ # {
562
+ # "name": "Dave",
563
+ # "age" :40,
564
+ # "hats": [
565
+ # "Cattleman's",
566
+ # "Panama",
567
+ # "Tophat"
568
+ # ]
569
+ # }
570
+ # JSON
571
+ #
572
+ # Load a \String:
573
+ # ruby = JSON.load(source)
574
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
575
+ #
576
+ # Load an \IO object:
577
+ # require 'stringio'
578
+ # object = JSON.load(StringIO.new(source))
579
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
580
+ #
581
+ # Load a \File object:
582
+ # path = 't.json'
583
+ # File.write(path, source)
584
+ # File.open(path) do |file|
585
+ # JSON.load(file)
586
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
587
+ #
588
+ # ---
589
+ #
590
+ # When +proc+ is given:
591
+ # - Modifies +source+ as above.
592
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
593
+ # - Recursively calls <tt>proc(result)</tt>.
594
+ # - Returns the final result.
595
+ #
596
+ # Example:
597
+ # require 'json'
598
+ #
599
+ # # Some classes for the example.
600
+ # class Base
601
+ # def initialize(attributes)
602
+ # @attributes = attributes
603
+ # end
604
+ # end
605
+ # class User < Base; end
606
+ # class Account < Base; end
607
+ # class Admin < Base; end
608
+ # # The JSON source.
609
+ # json = <<-EOF
610
+ # {
611
+ # "users": [
612
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
613
+ # {"type": "User", "username": "john", "email": "john@example.com"}
614
+ # ],
615
+ # "accounts": [
616
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
617
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
618
+ # ],
619
+ # "admins": {"type": "Admin", "password": "0wn3d"}
620
+ # }
621
+ # EOF
622
+ # # Deserializer method.
623
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
624
+ # type = obj.is_a?(Hash) && obj["type"]
625
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
626
+ # end
627
+ # # Call to JSON.load
628
+ # ruby = JSON.load(json, proc {|obj|
629
+ # case obj
630
+ # when Hash
631
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
632
+ # when Array
633
+ # obj.map! {|v| deserialize_obj v }
634
+ # end
635
+ # obj
636
+ # })
637
+ # pp ruby
638
+ # Output:
639
+ # {"users"=>
640
+ # [#<User:0x00000000064c4c98
641
+ # @attributes=
642
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
643
+ # #<User:0x00000000064c4bd0
644
+ # @attributes=
645
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
646
+ # "accounts"=>
647
+ # [{"account"=>
648
+ # #<Account:0x00000000064c4928
649
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
650
+ # {"account"=>
651
+ # #<Account:0x00000000064c4680
652
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
653
+ # "admins"=>
654
+ # #<Admin:0x00000000064c41f8
655
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
656
+ #
657
+ # pkg:gem/json#lib/json/common.rb:701
658
+ def load(source, proc = T.unsafe(nil), allow_blank: T.unsafe(nil), **options); end
659
+
660
+ # :call-seq:
661
+ # JSON.load_file(path, **) -> object
662
+ #
663
+ # Calls:
664
+ # parse(File.read(path), **)
665
+ #
666
+ # See method #parse.
667
+ #
668
+ # pkg:gem/json#lib/json/common.rb:322
669
+ def load_file(filespec, **options); end
670
+
671
+ # :call-seq:
672
+ # JSON.load_file!(path, **)
673
+ #
674
+ # Calls:
675
+ # JSON.parse!(File.read(path), **)
676
+ #
677
+ # See method #parse!
678
+ #
679
+ # pkg:gem/json#lib/json/common.rb:333
680
+ def load_file!(filespec, **options); end
681
+
682
+ # :call-seq:
683
+ # JSON.parse(source, opts) -> object
684
+ #
685
+ # Returns the Ruby objects created by parsing the given +source+.
686
+ #
687
+ # Argument +source+ contains the \String to be parsed.
688
+ #
689
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
690
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
691
+ #
692
+ # ---
693
+ #
694
+ # When +source+ is a \JSON array, returns a Ruby \Array:
695
+ # source = '["foo", 1.0, true, false, null]'
696
+ # ruby = JSON.parse(source)
697
+ # ruby # => ["foo", 1.0, true, false, nil]
698
+ # ruby.class # => Array
699
+ #
700
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
701
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
702
+ # ruby = JSON.parse(source)
703
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
704
+ # ruby.class # => Hash
705
+ #
706
+ # For examples of parsing for all \JSON data types, see
707
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
708
+ #
709
+ # Parses nested JSON objects:
710
+ # source = <<~JSON
711
+ # {
712
+ # "name": "Dave",
713
+ # "age" :40,
714
+ # "hats": [
715
+ # "Cattleman's",
716
+ # "Panama",
717
+ # "Tophat"
718
+ # ]
719
+ # }
720
+ # JSON
721
+ # ruby = JSON.parse(source)
722
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
723
+ #
724
+ # ---
725
+ #
726
+ # Raises an exception if +source+ is not valid JSON:
727
+ # # Raises JSON::ParserError (unexpected character: 'invalid' at line 1 column 1):
728
+ # JSON.parse('invalid')
729
+ #
730
+ # pkg:gem/json#lib/json/common.rb:291
731
+ def parse(source, on_load: T.unsafe(nil), object_class: T.unsafe(nil), array_class: T.unsafe(nil), **options); end
732
+
733
+ # :call-seq:
734
+ # JSON.parse!(source, opts) -> object
735
+ #
736
+ # Calls
737
+ # parse(source, opts)
738
+ # with +source+ and possibly modified +opts+.
739
+ #
740
+ # Differences from JSON.parse:
741
+ # - Option +max_nesting+, if not provided, defaults to +false+,
742
+ # which disables checking for nesting depth.
743
+ # - Option +allow_nan+, if not provided, defaults to +true+.
744
+ #
745
+ # pkg:gem/json#lib/json/common.rb:311
746
+ def parse!(source, **options); end
747
+
748
+ # :call-seq:
749
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
750
+ #
751
+ # Arguments +obj+ and +opts+ here are the same as
752
+ # arguments +obj+ and +opts+ in JSON.generate.
753
+ #
754
+ # Default options are:
755
+ # {
756
+ # indent: ' ', # Two spaces
757
+ # space: ' ', # One space
758
+ # array_nl: "\n", # Newline
759
+ # object_nl: "\n" # Newline
760
+ # }
761
+ #
762
+ # Example:
763
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
764
+ # json = JSON.pretty_generate(obj)
765
+ # puts json
766
+ # Output:
767
+ # {
768
+ # "foo": [
769
+ # "bar",
770
+ # "baz"
771
+ # ],
772
+ # "bat": {
773
+ # "bam": 0,
774
+ # "bad": 1
775
+ # }
776
+ # }
777
+ #
778
+ # pkg:gem/json#lib/json/common.rb:419
779
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
780
+
781
+ # :call-seq:
782
+ # JSON.unsafe_load(source, options = {}) -> object
783
+ # JSON.unsafe_load(source, proc = nil, options = {}) -> object
784
+ #
785
+ # Returns the Ruby objects created by parsing the given +source+.
786
+ #
787
+ # BEWARE: This method is meant to deserialise data from trusted user input,
788
+ # like from your own database server or clients under your control, it could
789
+ # be dangerous to allow untrusted users to pass JSON sources into it.
790
+ #
791
+ # - Argument +source+ must be, or be convertible to, a \String:
792
+ # - If +source+ responds to instance method +to_str+,
793
+ # <tt>source.to_str</tt> becomes the source.
794
+ # - If +source+ responds to instance method +to_io+,
795
+ # <tt>source.to_io.read</tt> becomes the source.
796
+ # - If +source+ responds to instance method +read+,
797
+ # <tt>source.read</tt> becomes the source.
798
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
799
+ # - Option +allow_blank+ specifies a truthy value.
800
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
801
+ # - Otherwise, +source+ remains the source.
802
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
803
+ # It will be called recursively with each result (depth-first order).
804
+ # See details below.
805
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
806
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
807
+ #
808
+ # ---
809
+ #
810
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
811
+ # <tt>parse(source, opts)</tt>; see #parse.
812
+ #
813
+ # Source for following examples:
814
+ # source = <<~JSON
815
+ # {
816
+ # "name": "Dave",
817
+ # "age" :40,
818
+ # "hats": [
819
+ # "Cattleman's",
820
+ # "Panama",
821
+ # "Tophat"
822
+ # ]
823
+ # }
824
+ # JSON
825
+ #
826
+ # Load a \String:
827
+ # ruby = JSON.unsafe_load(source)
828
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
829
+ #
830
+ # Load an \IO object:
831
+ # require 'stringio'
832
+ # object = JSON.unsafe_load(StringIO.new(source))
833
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
834
+ #
835
+ # Load a \File object:
836
+ # path = 't.json'
837
+ # File.write(path, source)
838
+ # File.open(path) do |file|
839
+ # JSON.unsafe_load(file)
840
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
841
+ #
842
+ # ---
843
+ #
844
+ # When +proc+ is given:
845
+ # - Modifies +source+ as above.
846
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
847
+ # - Recursively calls <tt>proc(result)</tt>.
848
+ # - Returns the final result.
849
+ #
850
+ # Example:
851
+ # require 'json'
852
+ #
853
+ # # Some classes for the example.
854
+ # class Base
855
+ # def initialize(attributes)
856
+ # @attributes = attributes
857
+ # end
858
+ # end
859
+ # class User < Base; end
860
+ # class Account < Base; end
861
+ # class Admin < Base; end
862
+ # # The JSON source.
863
+ # json = <<-EOF
864
+ # {
865
+ # "users": [
866
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
867
+ # {"type": "User", "username": "john", "email": "john@example.com"}
868
+ # ],
869
+ # "accounts": [
870
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
871
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
872
+ # ],
873
+ # "admins": {"type": "Admin", "password": "0wn3d"}
874
+ # }
875
+ # EOF
876
+ # # Deserializer method.
877
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
878
+ # type = obj.is_a?(Hash) && obj["type"]
879
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
880
+ # end
881
+ # # Call to JSON.unsafe_load
882
+ # ruby = JSON.unsafe_load(json, proc {|obj|
883
+ # case obj
884
+ # when Hash
885
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
886
+ # when Array
887
+ # obj.map! {|v| deserialize_obj v }
888
+ # end
889
+ # obj
890
+ # })
891
+ # pp ruby
892
+ # Output:
893
+ # {"users"=>
894
+ # [#<User:0x00000000064c4c98
895
+ # @attributes=
896
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
897
+ # #<User:0x00000000064c4bd0
898
+ # @attributes=
899
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
900
+ # "accounts"=>
901
+ # [{"account"=>
902
+ # #<Account:0x00000000064c4928
903
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
904
+ # {"account"=>
905
+ # #<Account:0x00000000064c4680
906
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
907
+ # "admins"=>
908
+ # #<Admin:0x00000000064c41f8
909
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
910
+ #
911
+ # pkg:gem/json#lib/json/common.rb:571
912
+ def unsafe_load(source, proc = T.unsafe(nil), **options); end
913
+
914
+ class << self
915
+ # :call-seq:
916
+ # JSON[object] -> new_array or new_string
917
+ #
918
+ # If +object+ is a \String,
919
+ # calls JSON.parse with +object+ and +opts+ (see method #parse):
920
+ # json = '[0, 1, null]'
921
+ # JSON[json]# => [0, 1, nil]
922
+ #
923
+ # Otherwise, calls JSON.generate with +object+ and +opts+ (see method #generate):
924
+ # ruby = [0, 1, nil]
925
+ # JSON[ruby] # => '[0,1,null]'
926
+ #
927
+ # pkg:gem/json#lib/json/common.rb:54
928
+ def [](object, opts = T.unsafe(nil)); end
929
+
930
+ # :call-seq:
931
+ # JSON.dump(obj, io = nil, _deprecated_limit = nil, options = nil)
932
+ #
933
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
934
+ #
935
+ # - Argument +io+, if given, should respond to method +write+;
936
+ # the \JSON \String is written to +io+, and +io+ is returned.
937
+ # If +io+ is not given, the \JSON \String is returned.
938
+ # - Argument +_deprecated_limit+ is deprecated, pass the +:max_nesting+ option instead.
939
+ # ---
940
+ #
941
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
942
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
943
+ # json = JSON.dump(obj)
944
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
945
+ #
946
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
947
+ # path = 't.json'
948
+ # File.open(path, 'w') do |file|
949
+ # JSON.dump(obj, file)
950
+ # end # => #<File:t.json (closed)>
951
+ # puts File.read(path)
952
+ # Output:
953
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
954
+ #
955
+ # pkg:gem/json#lib/json/common.rb:747
956
+ def dump(obj, anIO = T.unsafe(nil), _deprecated_limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
957
+
958
+ # :call-seq:
959
+ # JSON.generate(obj, opts = nil) -> new_string
960
+ #
961
+ # Returns a \String containing the generated \JSON data.
962
+ #
963
+ # See also JSON.pretty_generate.
964
+ #
965
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
966
+ #
967
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
968
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
969
+ #
970
+ # ---
971
+ #
972
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
973
+ # obj = ["foo", 1.0, true, false, nil]
974
+ # json = JSON.generate(obj)
975
+ # json # => '["foo",1.0,true,false,null]'
976
+ #
977
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
978
+ # obj = {foo: 0, bar: 's', baz: :bat}
979
+ # json = JSON.generate(obj)
980
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
981
+ #
982
+ # For examples of generating from other Ruby objects, see
983
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
984
+ #
985
+ # ---
986
+ #
987
+ # Raises an exception if any formatting option is not a \String.
988
+ #
989
+ # Raises an exception if +obj+ contains circular references:
990
+ # a = []; b = []; a.push(b); b.push(a)
991
+ # # Raises JSON::NestingError (nesting of 100 is too deep. Did you try to serialize objects with circular references?):
992
+ # JSON.generate(a)
993
+ #
994
+ # pkg:gem/json#lib/json/common.rb:373
995
+ def generate(obj, opts = T.unsafe(nil)); end
996
+
997
+ # Returns the JSON generator module that is used by JSON.
998
+ #
999
+ # pkg:gem/json#lib/json/common.rb:104
1000
+ def generator; end
1001
+
1002
+ # Set the module _generator_ to be used by JSON.
1003
+ #
1004
+ # pkg:gem/json#lib/json/common.rb:80
1005
+ def generator=(generator); end
1006
+
1007
+ # :call-seq:
1008
+ # JSON.load(source, options = {}) -> object
1009
+ # JSON.load(source, proc = nil, options = {}) -> object
1010
+ #
1011
+ # Returns the Ruby objects created by parsing the given +source+.
1012
+ #
1013
+ # - Argument +source+ must be, or be convertible to, a \String:
1014
+ # - If +source+ responds to instance method +to_str+,
1015
+ # <tt>source.to_str</tt> becomes the source.
1016
+ # - If +source+ responds to instance method +to_io+,
1017
+ # <tt>source.to_io.read</tt> becomes the source.
1018
+ # - If +source+ responds to instance method +read+,
1019
+ # <tt>source.read</tt> becomes the source.
1020
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1021
+ # - Option +allow_blank+ specifies a truthy value.
1022
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1023
+ # - Otherwise, +source+ remains the source.
1024
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1025
+ # It will be called recursively with each result (depth-first order).
1026
+ # See details below.
1027
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1028
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1029
+ #
1030
+ # ---
1031
+ #
1032
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
1033
+ # <tt>parse(source, opts)</tt>; see #parse.
1034
+ #
1035
+ # Source for following examples:
1036
+ # source = <<~JSON
1037
+ # {
1038
+ # "name": "Dave",
1039
+ # "age" :40,
1040
+ # "hats": [
1041
+ # "Cattleman's",
1042
+ # "Panama",
1043
+ # "Tophat"
1044
+ # ]
1045
+ # }
1046
+ # JSON
1047
+ #
1048
+ # Load a \String:
1049
+ # ruby = JSON.load(source)
1050
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1051
+ #
1052
+ # Load an \IO object:
1053
+ # require 'stringio'
1054
+ # object = JSON.load(StringIO.new(source))
1055
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1056
+ #
1057
+ # Load a \File object:
1058
+ # path = 't.json'
1059
+ # File.write(path, source)
1060
+ # File.open(path) do |file|
1061
+ # JSON.load(file)
1062
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1063
+ #
1064
+ # ---
1065
+ #
1066
+ # When +proc+ is given:
1067
+ # - Modifies +source+ as above.
1068
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1069
+ # - Recursively calls <tt>proc(result)</tt>.
1070
+ # - Returns the final result.
1071
+ #
1072
+ # Example:
1073
+ # require 'json'
1074
+ #
1075
+ # # Some classes for the example.
1076
+ # class Base
1077
+ # def initialize(attributes)
1078
+ # @attributes = attributes
1079
+ # end
1080
+ # end
1081
+ # class User < Base; end
1082
+ # class Account < Base; end
1083
+ # class Admin < Base; end
1084
+ # # The JSON source.
1085
+ # json = <<-EOF
1086
+ # {
1087
+ # "users": [
1088
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
1089
+ # {"type": "User", "username": "john", "email": "john@example.com"}
1090
+ # ],
1091
+ # "accounts": [
1092
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1093
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1094
+ # ],
1095
+ # "admins": {"type": "Admin", "password": "0wn3d"}
1096
+ # }
1097
+ # EOF
1098
+ # # Deserializer method.
1099
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1100
+ # type = obj.is_a?(Hash) && obj["type"]
1101
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1102
+ # end
1103
+ # # Call to JSON.load
1104
+ # ruby = JSON.load(json, proc {|obj|
1105
+ # case obj
1106
+ # when Hash
1107
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
1108
+ # when Array
1109
+ # obj.map! {|v| deserialize_obj v }
1110
+ # end
1111
+ # obj
1112
+ # })
1113
+ # pp ruby
1114
+ # Output:
1115
+ # {"users"=>
1116
+ # [#<User:0x00000000064c4c98
1117
+ # @attributes=
1118
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1119
+ # #<User:0x00000000064c4bd0
1120
+ # @attributes=
1121
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1122
+ # "accounts"=>
1123
+ # [{"account"=>
1124
+ # #<Account:0x00000000064c4928
1125
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1126
+ # {"account"=>
1127
+ # #<Account:0x00000000064c4680
1128
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1129
+ # "admins"=>
1130
+ # #<Admin:0x00000000064c41f8
1131
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1132
+ #
1133
+ # pkg:gem/json#lib/json/common.rb:701
1134
+ def load(source, proc = T.unsafe(nil), allow_blank: T.unsafe(nil), **options); end
1135
+
1136
+ # :call-seq:
1137
+ # JSON.load_file(path, **) -> object
1138
+ #
1139
+ # Calls:
1140
+ # parse(File.read(path), **)
1141
+ #
1142
+ # See method #parse.
1143
+ #
1144
+ # pkg:gem/json#lib/json/common.rb:322
1145
+ def load_file(filespec, **options); end
1146
+
1147
+ # :call-seq:
1148
+ # JSON.load_file!(path, **)
1149
+ #
1150
+ # Calls:
1151
+ # JSON.parse!(File.read(path), **)
1152
+ #
1153
+ # See method #parse!
1154
+ #
1155
+ # pkg:gem/json#lib/json/common.rb:333
1156
+ def load_file!(filespec, **options); end
1157
+
1158
+ # :call-seq:
1159
+ # JSON.parse(source, opts) -> object
1160
+ #
1161
+ # Returns the Ruby objects created by parsing the given +source+.
1162
+ #
1163
+ # Argument +source+ contains the \String to be parsed.
1164
+ #
1165
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
1166
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1167
+ #
1168
+ # ---
1169
+ #
1170
+ # When +source+ is a \JSON array, returns a Ruby \Array:
1171
+ # source = '["foo", 1.0, true, false, null]'
1172
+ # ruby = JSON.parse(source)
1173
+ # ruby # => ["foo", 1.0, true, false, nil]
1174
+ # ruby.class # => Array
1175
+ #
1176
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
1177
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
1178
+ # ruby = JSON.parse(source)
1179
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
1180
+ # ruby.class # => Hash
1181
+ #
1182
+ # For examples of parsing for all \JSON data types, see
1183
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
1184
+ #
1185
+ # Parses nested JSON objects:
1186
+ # source = <<~JSON
1187
+ # {
1188
+ # "name": "Dave",
1189
+ # "age" :40,
1190
+ # "hats": [
1191
+ # "Cattleman's",
1192
+ # "Panama",
1193
+ # "Tophat"
1194
+ # ]
1195
+ # }
1196
+ # JSON
1197
+ # ruby = JSON.parse(source)
1198
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1199
+ #
1200
+ # ---
1201
+ #
1202
+ # Raises an exception if +source+ is not valid JSON:
1203
+ # # Raises JSON::ParserError (unexpected character: 'invalid' at line 1 column 1):
1204
+ # JSON.parse('invalid')
1205
+ #
1206
+ # pkg:gem/json#lib/json/common.rb:291
1207
+ def parse(source, on_load: T.unsafe(nil), object_class: T.unsafe(nil), array_class: T.unsafe(nil), **options); end
1208
+
1209
+ # :call-seq:
1210
+ # JSON.parse!(source, opts) -> object
1211
+ #
1212
+ # Calls
1213
+ # parse(source, opts)
1214
+ # with +source+ and possibly modified +opts+.
1215
+ #
1216
+ # Differences from JSON.parse:
1217
+ # - Option +max_nesting+, if not provided, defaults to +false+,
1218
+ # which disables checking for nesting depth.
1219
+ # - Option +allow_nan+, if not provided, defaults to +true+.
1220
+ #
1221
+ # pkg:gem/json#lib/json/common.rb:311
1222
+ def parse!(source, **options); end
1223
+
1224
+ # Returns the JSON parser class that is used by JSON.
1225
+ #
1226
+ # pkg:gem/json#lib/json/common.rb:70
1227
+ def parser; end
1228
+
1229
+ # Set the JSON parser class _parser_ to be used by JSON.
1230
+ #
1231
+ # pkg:gem/json#lib/json/common.rb:73
1232
+ def parser=(parser); end
1233
+
1234
+ # :call-seq:
1235
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
1236
+ #
1237
+ # Arguments +obj+ and +opts+ here are the same as
1238
+ # arguments +obj+ and +opts+ in JSON.generate.
1239
+ #
1240
+ # Default options are:
1241
+ # {
1242
+ # indent: ' ', # Two spaces
1243
+ # space: ' ', # One space
1244
+ # array_nl: "\n", # Newline
1245
+ # object_nl: "\n" # Newline
1246
+ # }
1247
+ #
1248
+ # Example:
1249
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
1250
+ # json = JSON.pretty_generate(obj)
1251
+ # puts json
1252
+ # Output:
1253
+ # {
1254
+ # "foo": [
1255
+ # "bar",
1256
+ # "baz"
1257
+ # ],
1258
+ # "bat": {
1259
+ # "bam": 0,
1260
+ # "bad": 1
1261
+ # }
1262
+ # }
1263
+ #
1264
+ # pkg:gem/json#lib/json/common.rb:419
1265
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
1266
+
1267
+ # Sets or Returns the JSON generator state class that is used by JSON.
1268
+ #
1269
+ # pkg:gem/json#lib/json/common.rb:107
1270
+ def state; end
1271
+
1272
+ # Sets or Returns the JSON generator state class that is used by JSON.
1273
+ #
1274
+ # pkg:gem/json#lib/json/common.rb:107
1275
+ def state=(_arg0); end
1276
+
1277
+ # :call-seq:
1278
+ # JSON.unsafe_load(source, options = {}) -> object
1279
+ # JSON.unsafe_load(source, proc = nil, options = {}) -> object
1280
+ #
1281
+ # Returns the Ruby objects created by parsing the given +source+.
1282
+ #
1283
+ # BEWARE: This method is meant to deserialise data from trusted user input,
1284
+ # like from your own database server or clients under your control, it could
1285
+ # be dangerous to allow untrusted users to pass JSON sources into it.
1286
+ #
1287
+ # - Argument +source+ must be, or be convertible to, a \String:
1288
+ # - If +source+ responds to instance method +to_str+,
1289
+ # <tt>source.to_str</tt> becomes the source.
1290
+ # - If +source+ responds to instance method +to_io+,
1291
+ # <tt>source.to_io.read</tt> becomes the source.
1292
+ # - If +source+ responds to instance method +read+,
1293
+ # <tt>source.read</tt> becomes the source.
1294
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1295
+ # - Option +allow_blank+ specifies a truthy value.
1296
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1297
+ # - Otherwise, +source+ remains the source.
1298
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1299
+ # It will be called recursively with each result (depth-first order).
1300
+ # See details below.
1301
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1302
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1303
+ #
1304
+ # ---
1305
+ #
1306
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
1307
+ # <tt>parse(source, opts)</tt>; see #parse.
1308
+ #
1309
+ # Source for following examples:
1310
+ # source = <<~JSON
1311
+ # {
1312
+ # "name": "Dave",
1313
+ # "age" :40,
1314
+ # "hats": [
1315
+ # "Cattleman's",
1316
+ # "Panama",
1317
+ # "Tophat"
1318
+ # ]
1319
+ # }
1320
+ # JSON
1321
+ #
1322
+ # Load a \String:
1323
+ # ruby = JSON.unsafe_load(source)
1324
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1325
+ #
1326
+ # Load an \IO object:
1327
+ # require 'stringio'
1328
+ # object = JSON.unsafe_load(StringIO.new(source))
1329
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1330
+ #
1331
+ # Load a \File object:
1332
+ # path = 't.json'
1333
+ # File.write(path, source)
1334
+ # File.open(path) do |file|
1335
+ # JSON.unsafe_load(file)
1336
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1337
+ #
1338
+ # ---
1339
+ #
1340
+ # When +proc+ is given:
1341
+ # - Modifies +source+ as above.
1342
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1343
+ # - Recursively calls <tt>proc(result)</tt>.
1344
+ # - Returns the final result.
1345
+ #
1346
+ # Example:
1347
+ # require 'json'
1348
+ #
1349
+ # # Some classes for the example.
1350
+ # class Base
1351
+ # def initialize(attributes)
1352
+ # @attributes = attributes
1353
+ # end
1354
+ # end
1355
+ # class User < Base; end
1356
+ # class Account < Base; end
1357
+ # class Admin < Base; end
1358
+ # # The JSON source.
1359
+ # json = <<-EOF
1360
+ # {
1361
+ # "users": [
1362
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
1363
+ # {"type": "User", "username": "john", "email": "john@example.com"}
1364
+ # ],
1365
+ # "accounts": [
1366
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1367
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1368
+ # ],
1369
+ # "admins": {"type": "Admin", "password": "0wn3d"}
1370
+ # }
1371
+ # EOF
1372
+ # # Deserializer method.
1373
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1374
+ # type = obj.is_a?(Hash) && obj["type"]
1375
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1376
+ # end
1377
+ # # Call to JSON.unsafe_load
1378
+ # ruby = JSON.unsafe_load(json, proc {|obj|
1379
+ # case obj
1380
+ # when Hash
1381
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
1382
+ # when Array
1383
+ # obj.map! {|v| deserialize_obj v }
1384
+ # end
1385
+ # obj
1386
+ # })
1387
+ # pp ruby
1388
+ # Output:
1389
+ # {"users"=>
1390
+ # [#<User:0x00000000064c4c98
1391
+ # @attributes=
1392
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1393
+ # #<User:0x00000000064c4bd0
1394
+ # @attributes=
1395
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1396
+ # "accounts"=>
1397
+ # [{"account"=>
1398
+ # #<Account:0x00000000064c4928
1399
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1400
+ # {"account"=>
1401
+ # #<Account:0x00000000064c4680
1402
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1403
+ # "admins"=>
1404
+ # #<Admin:0x00000000064c41f8
1405
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1406
+ #
1407
+ # pkg:gem/json#lib/json/common.rb:571
1408
+ def unsafe_load(source, proc = T.unsafe(nil), **options); end
1409
+
1410
+ private
1411
+
1412
+ # Called from the extension when a hash has both string and symbol keys
1413
+ #
1414
+ # pkg:gem/json#lib/json/common.rb:112
1415
+ def on_mixed_keys_hash(hash); end
1416
+ end
1417
+ end
1418
+
1419
+ # JSON::Coder holds a parser and generator configuration.
1420
+ #
1421
+ # module MyApp
1422
+ # JSONC_CODER = JSON::Coder.new(
1423
+ # allow_trailing_comma: true
1424
+ # )
1425
+ # end
1426
+ #
1427
+ # MyApp::JSONC_CODER.load(document)
1428
+ #
1429
+ # pkg:gem/json#lib/json/common.rb:787
1430
+ class JSON::Coder
1431
+ # :call-seq:
1432
+ # JSON::Coder.new(**options, &block)
1433
+ #
1434
+ # Keyword arguments +options+, if given, are options for both parsing and generating.
1435
+ # See {Parsing Options}[rdoc-ref:JSON@Parsing+Options],
1436
+ # and {Generating Options}[rdoc-ref:JSON@Generating+Options].
1437
+ #
1438
+ # For generation, the <tt>strict: true</tt> option is always set. When a Ruby object with no native \JSON counterpart is
1439
+ # encountered, the block provided to the initialize method is invoked, and must return a Ruby object that has a native
1440
+ # \JSON counterpart:
1441
+ #
1442
+ # module MyApp
1443
+ # API_JSON_CODER = JSON::Coder.new do |object|
1444
+ # case object
1445
+ # when Time
1446
+ # object.iso8601(3)
1447
+ # else
1448
+ # object # Unknown type, will raise
1449
+ # end
1450
+ # end
1451
+ # end
1452
+ #
1453
+ # puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
1454
+ #
1455
+ # The conversion callback can also be passed as +as_json:+. If both are given, the block takes precedence.
1456
+ # Passing +false+ or +nil+ for +strict:+ raises ArgumentError.
1457
+ #
1458
+ # pkg:gem/json#lib/json/common.rb:836
1459
+ def initialize(object_class: T.unsafe(nil), array_class: T.unsafe(nil), on_load: T.unsafe(nil), strict: T.unsafe(nil), **options, &as_json); end
1460
+
1461
+ # call-seq:
1462
+ # dump(object) -> String
1463
+ # dump(object, io) -> io
1464
+ #
1465
+ # Serialize the given object into a \JSON document.
1466
+ #
1467
+ # pkg:gem/json#lib/json/common.rb:859
1468
+ def dump(object, io = T.unsafe(nil)); end
1469
+
1470
+ # pkg:gem/json#lib/json/common.rb:862
1471
+ def generate(object, io = T.unsafe(nil)); end
1472
+
1473
+ # call-seq:
1474
+ # load(string) -> Object
1475
+ #
1476
+ # Parse the given \JSON document and return an equivalent Ruby object.
1477
+ #
1478
+ # pkg:gem/json#lib/json/common.rb:868
1479
+ def load(source); end
1480
+
1481
+ # call-seq:
1482
+ # load(path) -> Object
1483
+ #
1484
+ # Parse the given \JSON document and return an equivalent Ruby object.
1485
+ #
1486
+ # pkg:gem/json#lib/json/common.rb:877
1487
+ def load_file(path); end
1488
+
1489
+ # pkg:gem/json#lib/json/common.rb:871
1490
+ def parse(source); end
1491
+ end
1492
+
1493
+ # pkg:gem/json#lib/json/common.rb:802
1494
+ JSON::Coder::EXCLUDED_GENERATOR_OPTIONS = T.let(T.unsafe(nil), Array)
1495
+
1496
+ # pkg:gem/json#lib/json/common.rb:788
1497
+ JSON::Coder::PARSER_OPTIONS = T.let(T.unsafe(nil), Array)
1498
+
1499
+ # This module holds all the modules/classes that implement JSON's
1500
+ # functionality as C extensions.
1501
+ #
1502
+ # pkg:gem/json#lib/json/ext.rb:8
1503
+ module JSON::Ext
1504
+ class << self
1505
+ # pkg:gem/json#lib/json/ext.rb:46
1506
+ def coerce_key(key, as_json); end
1507
+
1508
+ # pkg:gem/json#lib/json/ext.rb:80
1509
+ def on_duplicate_key(hash, as_json); end
1510
+
1511
+ # pkg:gem/json#lib/json/ext.rb:37
1512
+ def shareable_lambda(block); end
1513
+
1514
+ # pkg:gem/json#lib/json/ext.rb:42
1515
+ def valid_encoding?(str); end
1516
+ end
1517
+ end
1518
+
1519
+ # pkg:gem/json#lib/json/ext.rb:101
1520
+ class JSON::Ext::Generator::State
1521
+ # call-seq: new(opts = {})
1522
+ #
1523
+ # Instantiates a new State object, configured by _opts_.
1524
+ #
1525
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
1526
+ # See {Generating Options}[rdoc-ref:JSON@Generating+Options].
1527
+ #
1528
+ # pkg:gem/json#lib/json/ext.rb:101
1529
+ def initialize(opts = T.unsafe(nil)); end
1530
+
1531
+ # pkg:gem/json#lib/json/ext.rb:101
1532
+ def _generate_no_fallback(*_arg0); end
1533
+
1534
+ # pkg:gem/json#lib/json/ext.rb:101
1535
+ def allow_nan=(_arg0); end
1536
+
1537
+ # pkg:gem/json#lib/json/ext.rb:101
1538
+ def allow_nan?; end
1539
+
1540
+ # pkg:gem/json#lib/json/ext.rb:101
1541
+ def array_nl; end
1542
+
1543
+ # pkg:gem/json#lib/json/ext.rb:101
1544
+ def array_nl=(_arg0); end
1545
+
1546
+ # pkg:gem/json#lib/json/ext.rb:101
1547
+ def as_json; end
1548
+
1549
+ # pkg:gem/json#lib/json/ext.rb:101
1550
+ def as_json=(_arg0); end
1551
+
1552
+ # pkg:gem/json#lib/json/ext.rb:101
1553
+ def ascii_only=(_arg0); end
1554
+
1555
+ # pkg:gem/json#lib/json/ext.rb:101
1556
+ def ascii_only?; end
1557
+
1558
+ # pkg:gem/json#lib/json/ext.rb:101
1559
+ def buffer_initial_length; end
1560
+
1561
+ # pkg:gem/json#lib/json/ext.rb:101
1562
+ def buffer_initial_length=(_arg0); end
1563
+
1564
+ # pkg:gem/json#lib/json/ext.rb:101
1565
+ def check_circular?; end
1566
+
1567
+ # call-seq: configure(opts)
1568
+ #
1569
+ # Configure this State instance with the Hash _opts_, and return
1570
+ # itself.
1571
+ #
1572
+ # pkg:gem/json#lib/json/ext/generator/state.rb:23
1573
+ def configure(opts); end
1574
+
1575
+ # pkg:gem/json#lib/json/ext.rb:101
1576
+ def depth; end
1577
+
1578
+ # pkg:gem/json#lib/json/ext.rb:101
1579
+ def depth=(_arg0); end
1580
+
1581
+ # pkg:gem/json#lib/json/ext.rb:101
1582
+ def generate(*_arg0); end
1583
+
1584
+ # pkg:gem/json#lib/json/ext.rb:101
1585
+ def indent; end
1586
+
1587
+ # pkg:gem/json#lib/json/ext.rb:101
1588
+ def indent=(_arg0); end
1589
+
1590
+ # pkg:gem/json#lib/json/ext.rb:101
1591
+ def max_nesting; end
1592
+
1593
+ # pkg:gem/json#lib/json/ext.rb:101
1594
+ def max_nesting=(_arg0); end
1595
+
1596
+ # pkg:gem/json#lib/json/ext/generator/state.rb:36
1597
+ def merge(opts); end
1598
+
1599
+ # pkg:gem/json#lib/json/ext.rb:101
1600
+ def object_nl; end
1601
+
1602
+ # pkg:gem/json#lib/json/ext.rb:101
1603
+ def object_nl=(_arg0); end
1604
+
1605
+ # pkg:gem/json#lib/json/ext.rb:101
1606
+ def rfc8785=(_arg0); end
1607
+
1608
+ # pkg:gem/json#lib/json/ext.rb:101
1609
+ def rfc8785?; end
1610
+
1611
+ # pkg:gem/json#lib/json/ext.rb:101
1612
+ def script_safe; end
1613
+
1614
+ # pkg:gem/json#lib/json/ext.rb:101
1615
+ def script_safe=(_arg0); end
1616
+
1617
+ # pkg:gem/json#lib/json/ext.rb:101
1618
+ def script_safe?; end
1619
+
1620
+ # pkg:gem/json#lib/json/ext.rb:101
1621
+ def sort_keys; end
1622
+
1623
+ # pkg:gem/json#lib/json/ext.rb:101
1624
+ def sort_keys=(_arg0); end
1625
+
1626
+ # pkg:gem/json#lib/json/ext.rb:101
1627
+ def space; end
1628
+
1629
+ # pkg:gem/json#lib/json/ext.rb:101
1630
+ def space=(_arg0); end
1631
+
1632
+ # pkg:gem/json#lib/json/ext.rb:101
1633
+ def space_before; end
1634
+
1635
+ # pkg:gem/json#lib/json/ext.rb:101
1636
+ def space_before=(_arg0); end
1637
+
1638
+ # pkg:gem/json#lib/json/ext.rb:101
1639
+ def strict; end
1640
+
1641
+ # pkg:gem/json#lib/json/ext.rb:101
1642
+ def strict=(_arg0); end
1643
+
1644
+ # pkg:gem/json#lib/json/ext.rb:101
1645
+ def strict?; end
1646
+
1647
+ # call-seq: to_h
1648
+ #
1649
+ # Returns the configuration instance variables as a hash, that can be
1650
+ # passed to the configure method.
1651
+ #
1652
+ # pkg:gem/json#lib/json/ext/generator/state.rb:42
1653
+ def to_h; end
1654
+
1655
+ # pkg:gem/json#lib/json/ext/generator/state.rb:69
1656
+ def to_hash; end
1657
+
1658
+ private
1659
+
1660
+ # pkg:gem/json#lib/json/ext.rb:101
1661
+ def _configure(_arg0); end
1662
+
1663
+ # pkg:gem/json#lib/json/ext.rb:101
1664
+ def allow_duplicate_key?; end
1665
+
1666
+ # pkg:gem/json#lib/json/ext.rb:101
1667
+ def initialize_copy(_arg0); end
1668
+
1669
+ class << self
1670
+ # pkg:gem/json#lib/json/ext.rb:101
1671
+ def _generate_no_fallback(_arg0, _arg1, _arg2); end
1672
+
1673
+ # pkg:gem/json#lib/json/ext.rb:101
1674
+ def default_sort_keys_proc=(_arg0); end
1675
+
1676
+ # pkg:gem/json#lib/json/ext.rb:101
1677
+ def from_state(_arg0); end
1678
+
1679
+ # pkg:gem/json#lib/json/ext.rb:101
1680
+ def generate(_arg0, _arg1, _arg2); end
1681
+
1682
+ # pkg:gem/json#lib/json/ext.rb:101
1683
+ def rfc8785_number_formatter_proc=(_arg0); end
1684
+
1685
+ # pkg:gem/json#lib/json/ext.rb:101
1686
+ def rfc8785_sort_keys_proc=(_arg0); end
1687
+ end
1688
+ end
1689
+
1690
+ # pkg:gem/json#lib/json/ext.rb:9
1691
+ class JSON::Ext::Parser
1692
+ # pkg:gem/json#lib/json/ext.rb:17
1693
+ def initialize(source, opts = T.unsafe(nil)); end
1694
+
1695
+ # pkg:gem/json#lib/json/ext.rb:26
1696
+ def parse; end
1697
+
1698
+ # pkg:gem/json#lib/json/ext.rb:22
1699
+ def source; end
1700
+
1701
+ class << self
1702
+ # pkg:gem/json#lib/json/ext.rb:11
1703
+ def parse(_arg0, _arg1); end
1704
+ end
1705
+ end
1706
+
1707
+ # pkg:gem/json#lib/json/ext.rb:94
1708
+ JSON::Ext::Parser::Config = JSON::Ext::ParserConfig
1709
+
1710
+ # pkg:gem/json#lib/json/ext.rb:93
1711
+ class JSON::Ext::ParserConfig
1712
+ # pkg:gem/json#lib/json/ext.rb:93
1713
+ def initialize(_arg0); end
1714
+
1715
+ # pkg:gem/json#lib/json/ext.rb:93
1716
+ def parse(_arg0); end
1717
+ end
1718
+
1719
+ # Fragment of JSON document that is to be included as is:
1720
+ # fragment = JSON::Fragment.new("[1, 2, 3]")
1721
+ # JSON.generate({ count: 3, items: fragments })
1722
+ #
1723
+ # This allows to easily assemble multiple JSON fragments that have
1724
+ # been persisted somewhere without having to parse them nor resorting
1725
+ # to string interpolation.
1726
+ #
1727
+ # Note: no validation is performed on the provided string. It is the
1728
+ # responsibility of the caller to ensure the string contains valid JSON.
1729
+ #
1730
+ # pkg:gem/json#lib/json/common.rb:227
1731
+ class JSON::Fragment < ::Struct
1732
+ # pkg:gem/json#lib/json/common.rb:228
1733
+ def initialize(json); end
1734
+
1735
+ # pkg:gem/json#lib/json/common.rb:227
1736
+ def json; end
1737
+
1738
+ # pkg:gem/json#lib/json/common.rb:227
1739
+ def json=(_); end
1740
+
1741
+ # pkg:gem/json#lib/json/common.rb:236
1742
+ def to_json(state = T.unsafe(nil), *); end
1743
+
1744
+ class << self
1745
+ # pkg:gem/json#lib/json/common.rb:227
1746
+ def [](*_arg0); end
1747
+
1748
+ # pkg:gem/json#lib/json/common.rb:227
1749
+ def inspect; end
1750
+
1751
+ # pkg:gem/json#lib/json/common.rb:227
1752
+ def keyword_init?; end
1753
+
1754
+ # pkg:gem/json#lib/json/common.rb:227
1755
+ def members; end
1756
+
1757
+ # pkg:gem/json#lib/json/common.rb:227
1758
+ def new(*_arg0); end
1759
+ end
1760
+ end
1761
+
1762
+ # This exception is raised if a generator or unparser error occurs.
1763
+ #
1764
+ # pkg:gem/json#lib/json/common.rb:197
1765
+ class JSON::GeneratorError < ::JSON::JSONError
1766
+ # pkg:gem/json#lib/json/common.rb:200
1767
+ def initialize(message, invalid_object = T.unsafe(nil)); end
1768
+
1769
+ # pkg:gem/json#lib/json/common.rb:205
1770
+ def detailed_message(*, **, &); end
1771
+
1772
+ # pkg:gem/json#lib/json/common.rb:198
1773
+ def invalid_object; end
1774
+ end
1775
+
1776
+ # pkg:gem/json#lib/json/common.rb:882
1777
+ module JSON::GeneratorMethods
1778
+ # call-seq: to_json(*)
1779
+ #
1780
+ # Converts this object into a JSON string.
1781
+ # If this object doesn't directly maps to a JSON native type,
1782
+ # first convert it to a string (calling #to_s), then converts
1783
+ # it to a JSON string, and returns the result.
1784
+ # This is a fallback, if no special method #to_json was defined for some object.
1785
+ #
1786
+ # pkg:gem/json#lib/json/common.rb:890
1787
+ def to_json(state = T.unsafe(nil), *); end
1788
+ end
1789
+
1790
+ # pkg:gem/json#lib/json/common.rb:381
1791
+ JSON::PRETTY_GENERATE_OPTIONS = T.let(T.unsafe(nil), Hash)
1792
+
1793
+ # pkg:gem/json#lib/json/common.rb:76
1794
+ JSON::Parser = JSON::Ext::Parser
1795
+
1796
+ # This exception is raised if a parser error occurs.
1797
+ #
1798
+ # pkg:gem/json#lib/json/common.rb:136
1799
+ class JSON::ParserError < ::JSON::JSONError
1800
+ # One-based column number where the parser encountered an error, counted in Unicode codepoints.
1801
+ # Is +nil+ when raised by JSON::ResumableParser.
1802
+ #
1803
+ # pkg:gem/json#lib/json/common.rb:143
1804
+ def column; end
1805
+
1806
+ # Returns a best effort JSONPath string representing where in the document
1807
+ # the parser encountered an error:
1808
+ #
1809
+ # begin
1810
+ # JSON.parse('{"articles": [ { "title": invalid } ]}')
1811
+ # rescue JSON::ParserError => error
1812
+ # error.json_path # => "$.articles[0].title"
1813
+ # end
1814
+ #
1815
+ # pkg:gem/json#lib/json/common.rb:153
1816
+ def json_path; end
1817
+
1818
+ # Line number where the parser encountered an error.
1819
+ # Is +nil+ when raised by JSON::ResumableParser.
1820
+ #
1821
+ # pkg:gem/json#lib/json/common.rb:139
1822
+ def line; end
1823
+
1824
+ private
1825
+
1826
+ # pkg:gem/json#lib/json/common.rb:165
1827
+ def build_json_path(segments); end
1828
+ end
1829
+
1830
+ # pkg:gem/json#lib/json/common.rb:6
1831
+ module JSON::ParserOptions
1832
+ class << self
1833
+ # pkg:gem/json#lib/json/common.rb:8
1834
+ def on_load(on_load, object_class, array_class); end
1835
+
1836
+ private
1837
+
1838
+ # pkg:gem/json#lib/json/common.rb:27
1839
+ def array_class_proc(array_class, on_load); end
1840
+
1841
+ # pkg:gem/json#lib/json/common.rb:16
1842
+ def object_class_proc(object_class, on_load); end
1843
+ end
1844
+ end
1845
+
1846
+ # Not yet available on JRuby
1847
+ #
1848
+ # pkg:gem/json#lib/json/ext.rb:93
1849
+ class JSON::ResumableParser
1850
+ # pkg:gem/json#lib/json/ext.rb:93
1851
+ def initialize(*_arg0); end
1852
+
1853
+ # pkg:gem/json#lib/json/ext.rb:93
1854
+ def <<(_arg0); end
1855
+
1856
+ # pkg:gem/json#lib/json/ext.rb:93
1857
+ def clear; end
1858
+
1859
+ # Returns whether the parser is entirely done: no unconsumed bytes in
1860
+ # the buffer, no document under construction and no parsed value
1861
+ # awaiting retrieval.
1862
+ #
1863
+ # The main use case is detecting a truncated stream once the input is
1864
+ # exhausted:
1865
+ #
1866
+ # loop do
1867
+ # begin
1868
+ # parser << socket.readpartial(4096)
1869
+ # rescue EOFError
1870
+ # break
1871
+ # end
1872
+ # while parser.parse
1873
+ # process(parser.value)
1874
+ # end
1875
+ # end
1876
+ # warn "stream was truncated" unless parser.empty?
1877
+ #
1878
+ # pkg:gem/json#lib/json/ext.rb:190
1879
+ def empty?; end
1880
+
1881
+ # pkg:gem/json#lib/json/ext.rb:93
1882
+ def eos?; end
1883
+
1884
+ # pkg:gem/json#lib/json/ext.rb:93
1885
+ def parse; end
1886
+
1887
+ # pkg:gem/json#lib/json/ext.rb:93
1888
+ def parsed_bytes; end
1889
+
1890
+ # pkg:gem/json#lib/json/ext.rb:93
1891
+ def partial_value; end
1892
+
1893
+ # pkg:gem/json#lib/json/ext.rb:93
1894
+ def partial_value?; end
1895
+
1896
+ # pkg:gem/json#lib/json/ext.rb:93
1897
+ def rest; end
1898
+
1899
+ # pkg:gem/json#lib/json/ext.rb:93
1900
+ def value; end
1901
+
1902
+ # pkg:gem/json#lib/json/ext.rb:93
1903
+ def value?; end
1904
+ end
1905
+
1906
+ # pkg:gem/json#lib/json/common.rb:98
1907
+ JSON::State = JSON::Ext::Generator::State
1908
+
1909
+ # pkg:gem/json#lib/json/common.rb:907
1910
+ module Kernel
1911
+ private
1912
+
1913
+ # If _object_ is string-like, parse the string and return the parsed result as
1914
+ # a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
1915
+ # structure object and return it.
1916
+ #
1917
+ # The _opts_ argument is passed through to generate/parse respectively. See
1918
+ # generate and parse for their documentation.
1919
+ #
1920
+ # pkg:gem/json#lib/json/common.rb:916
1921
+ def JSON(object, opts = T.unsafe(nil)); end
1922
+ end
1923
+
1924
+ # pkg:gem/json#lib/json/common.rb:921
1925
+ class Object < ::BasicObject
1926
+ include ::Kernel
1927
+ include ::PP::ObjectMixin
1928
+ include ::JSON::GeneratorMethods
1929
+ end