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