phlex-stimulus 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 (147) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +16 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +341 -0
  6. data/Rakefile +12 -0
  7. data/lib/generators/phlex/stimulus/controller/USAGE +5 -0
  8. data/lib/generators/phlex/stimulus/controller/controller_generator.rb +49 -0
  9. data/lib/generators/phlex/stimulus/controller/templates/component.rb.erb +30 -0
  10. data/lib/generators/phlex/stimulus/controller/templates/controller.ts.erb +23 -0
  11. data/lib/generators/phlex/stimulus/generator_mixin.rb +21 -0
  12. data/lib/generators/phlex/stimulus/install/USAGE +5 -0
  13. data/lib/generators/phlex/stimulus/install/install_generator.rb +111 -0
  14. data/lib/generators/phlex/stimulus/install/templates/app/components/base.rb.erb +29 -0
  15. data/lib/generators/phlex/stimulus/install/templates/app/components/chain_controller.rb.erb +29 -0
  16. data/lib/generators/phlex/stimulus/install/templates/app/components/classlist_controller.rb.erb +30 -0
  17. data/lib/generators/phlex/stimulus/install/templates/app/components/controller.rb.erb +10 -0
  18. data/lib/generators/phlex/stimulus/install/templates/app/components/controller_chain.rb.erb +32 -0
  19. data/lib/generators/phlex/stimulus/install/templates/app/components/controller_template.rb.erb +24 -0
  20. data/lib/generators/phlex/stimulus/install/templates/app/components/log_controller.rb.erb +33 -0
  21. data/lib/generators/phlex/stimulus/install/templates/app/components/sleep_controller.rb.erb +30 -0
  22. data/lib/generators/phlex/stimulus/install/templates/app/components.rb.erb +7 -0
  23. data/lib/generators/phlex/stimulus/install/templates/app/javascript/application.ts.erb +5 -0
  24. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/application.ts.erb +10 -0
  25. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/chain_controller.ts.erb +32 -0
  26. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/chainable_controller.ts.erb +44 -0
  27. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/classlist_controller.ts.erb +30 -0
  28. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/index.ts.erb +4 -0
  29. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/log_controller.ts.erb +25 -0
  30. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/sleep_controller.ts.erb +19 -0
  31. data/lib/generators/phlex/stimulus/install/templates/app/javascript/controllers/typed_controller.ts.erb +53 -0
  32. data/lib/generators/phlex/stimulus/install/templates/app/javascript/utils/misc.ts.erb +37 -0
  33. data/lib/generators/phlex/stimulus/install/templates/app/javascript/utils/template.ts.erb +11 -0
  34. data/lib/phlex/stimulus/components/base.rb +81 -0
  35. data/lib/phlex/stimulus/components/controller.rb +170 -0
  36. data/lib/phlex/stimulus/components.rb +9 -0
  37. data/lib/phlex/stimulus/version.rb +8 -0
  38. data/lib/phlex/stimulus.rb +15 -0
  39. data/sorbet/config +7 -0
  40. data/sorbet/rbi/annotations/.gitattributes +1 -0
  41. data/sorbet/rbi/annotations/actionmailer.rbi +15 -0
  42. data/sorbet/rbi/annotations/actionpack.rbi +430 -0
  43. data/sorbet/rbi/annotations/actionview.rbi +75 -0
  44. data/sorbet/rbi/annotations/activejob.rbi +50 -0
  45. data/sorbet/rbi/annotations/activemodel.rbi +119 -0
  46. data/sorbet/rbi/annotations/activerecord.rbi +172 -0
  47. data/sorbet/rbi/annotations/activesupport.rbi +561 -0
  48. data/sorbet/rbi/annotations/globalid.rbi +30 -0
  49. data/sorbet/rbi/annotations/minitest.rbi +116 -0
  50. data/sorbet/rbi/annotations/railties.rbi +104 -0
  51. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  52. data/sorbet/rbi/dsl/.gitattributes +1 -0
  53. data/sorbet/rbi/dsl/active_support/callbacks.rbi +21 -0
  54. data/sorbet/rbi/gems/.gitattributes +1 -0
  55. data/sorbet/rbi/gems/action_text-trix@2.1.19.rbi +9 -0
  56. data/sorbet/rbi/gems/actioncable@8.1.3.rbi +9 -0
  57. data/sorbet/rbi/gems/actionmailbox@8.1.3.rbi +9 -0
  58. data/sorbet/rbi/gems/actionmailer@8.1.3.rbi +9 -0
  59. data/sorbet/rbi/gems/actionpack@8.1.3.rbi +20478 -0
  60. data/sorbet/rbi/gems/actiontext@8.1.3.rbi +9 -0
  61. data/sorbet/rbi/gems/actionview@8.1.3.rbi +14722 -0
  62. data/sorbet/rbi/gems/activejob@8.1.3.rbi +9 -0
  63. data/sorbet/rbi/gems/activemodel@8.1.3.rbi +9 -0
  64. data/sorbet/rbi/gems/activerecord@8.1.3.rbi +9 -0
  65. data/sorbet/rbi/gems/activestorage@8.1.3.rbi +9 -0
  66. data/sorbet/rbi/gems/activesupport@8.1.3.rbi +20153 -0
  67. data/sorbet/rbi/gems/ast@2.4.3.rbi +550 -0
  68. data/sorbet/rbi/gems/base64@0.3.0.rbi +545 -0
  69. data/sorbet/rbi/gems/benchmark@0.5.0.rbi +621 -0
  70. data/sorbet/rbi/gems/booleans@0.1.3.rbi +31 -0
  71. data/sorbet/rbi/gems/builder@3.3.0.rbi +9 -0
  72. data/sorbet/rbi/gems/byebug@12.0.0.rbi +49 -0
  73. data/sorbet/rbi/gems/concurrent-ruby@1.3.8.rbi +10656 -0
  74. data/sorbet/rbi/gems/connection_pool@3.0.2.rbi +9 -0
  75. data/sorbet/rbi/gems/crass@1.0.7.rbi +648 -0
  76. data/sorbet/rbi/gems/date@3.5.1.rbi +391 -0
  77. data/sorbet/rbi/gems/drb@2.2.3.rbi +9 -0
  78. data/sorbet/rbi/gems/erb@6.0.6.rbi +1600 -0
  79. data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
  80. data/sorbet/rbi/gems/globalid@1.4.0.rbi +9 -0
  81. data/sorbet/rbi/gems/i18n@1.15.2.rbi +2285 -0
  82. data/sorbet/rbi/gems/io-console@0.8.2.rbi +9 -0
  83. data/sorbet/rbi/gems/json@2.21.1.rbi +2289 -0
  84. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +189 -0
  85. data/sorbet/rbi/gems/logger@1.7.0.rbi +896 -0
  86. data/sorbet/rbi/gems/loofah@2.25.2.rbi +1134 -0
  87. data/sorbet/rbi/gems/mail@2.9.1.rbi +9 -0
  88. data/sorbet/rbi/gems/marcel@1.2.1.rbi +9 -0
  89. data/sorbet/rbi/gems/mini_mime@1.1.5.rbi +9 -0
  90. data/sorbet/rbi/gems/minitest@6.0.6.rbi +1482 -0
  91. data/sorbet/rbi/gems/net-imap@0.6.4.1.rbi +9 -0
  92. data/sorbet/rbi/gems/net-pop@0.1.2.rbi +9 -0
  93. data/sorbet/rbi/gems/net-protocol@0.2.2.rbi +244 -0
  94. data/sorbet/rbi/gems/net-smtp@0.5.1.rbi +9 -0
  95. data/sorbet/rbi/gems/netrc@0.11.0.rbi +147 -0
  96. data/sorbet/rbi/gems/nio4r@2.7.5.rbi +9 -0
  97. data/sorbet/rbi/gems/nokogiri@1.19.4.rbi +8168 -0
  98. data/sorbet/rbi/gems/parallel@1.28.0.rbi +270 -0
  99. data/sorbet/rbi/gems/phlex-rails@2.4.0.rbi +1945 -0
  100. data/sorbet/rbi/gems/phlex@2.4.1.rbi +1413 -0
  101. data/sorbet/rbi/gems/pp@0.6.4.rbi +387 -0
  102. data/sorbet/rbi/gems/prettyprint@0.2.0.rbi +455 -0
  103. data/sorbet/rbi/gems/prism@1.9.0.rbi +42226 -0
  104. data/sorbet/rbi/gems/racc@1.8.1.rbi +165 -0
  105. data/sorbet/rbi/gems/rack-session@2.1.2.rbi +756 -0
  106. data/sorbet/rbi/gems/rack-test@2.2.0.rbi +681 -0
  107. data/sorbet/rbi/gems/rack@3.2.6.rbi +4653 -0
  108. data/sorbet/rbi/gems/rackup@2.3.1.rbi +9 -0
  109. data/sorbet/rbi/gems/rails-dom-testing@2.3.0.rbi +517 -0
  110. data/sorbet/rbi/gems/rails-html-sanitizer@1.7.1.rbi +620 -0
  111. data/sorbet/rbi/gems/rails@8.1.3.rbi +9 -0
  112. data/sorbet/rbi/gems/railties@8.1.3.rbi +3507 -0
  113. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +362 -0
  114. data/sorbet/rbi/gems/rake@13.4.2.rbi +3130 -0
  115. data/sorbet/rbi/gems/rbi@0.4.0.rbi +5706 -0
  116. data/sorbet/rbi/gems/rbs@4.0.3.rbi +6908 -0
  117. data/sorbet/rbi/gems/refract@1.1.0.rbi +9 -0
  118. data/sorbet/rbi/gems/reline@0.6.3.rbi +2446 -0
  119. data/sorbet/rbi/gems/require-hooks@0.4.0.rbi +152 -0
  120. data/sorbet/rbi/gems/rexml@3.4.4.rbi +4905 -0
  121. data/sorbet/rbi/gems/rubocop-espago@1.3.0.rbi +9 -0
  122. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +988 -0
  123. data/sorbet/rbi/gems/rubydex@0.2.9.rbi +841 -0
  124. data/sorbet/rbi/gems/securerandom@0.4.1.rbi +75 -0
  125. data/sorbet/rbi/gems/shoulda-context@2.0.0.rbi +544 -0
  126. data/sorbet/rbi/gems/spoom@1.8.4.rbi +6738 -0
  127. data/sorbet/rbi/gems/tapioca@0.19.2.rbi +3599 -0
  128. data/sorbet/rbi/gems/thor@1.5.0.rbi +3870 -0
  129. data/sorbet/rbi/gems/timeout@0.6.1.rbi +200 -0
  130. data/sorbet/rbi/gems/tsort@0.2.0.rbi +389 -0
  131. data/sorbet/rbi/gems/tzinfo@2.0.6.rbi +5474 -0
  132. data/sorbet/rbi/gems/unicode-display_width@3.2.0.rbi +130 -0
  133. data/sorbet/rbi/gems/unicode-emoji@4.2.0.rbi +332 -0
  134. data/sorbet/rbi/gems/uri@1.1.1.rbi +2402 -0
  135. data/sorbet/rbi/gems/useragent@0.16.11.rbi +9 -0
  136. data/sorbet/rbi/gems/websocket-driver@0.8.2.rbi +9 -0
  137. data/sorbet/rbi/gems/websocket-extensions@0.1.5.rbi +9 -0
  138. data/sorbet/rbi/gems/zeitwerk@2.8.2.rbi +9 -0
  139. data/sorbet/rbi/shims/gems/parser.rbi +12 -0
  140. data/sorbet/rbi/shims/gems/rails.rbi +55 -0
  141. data/sorbet/rbi/shims/gems/refract.rbi +13 -0
  142. data/sorbet/rbi/shims/gems/shoulda-context.rbi +16 -0
  143. data/sorbet/tapioca/compilers/phlex_controller.rb +80 -0
  144. data/sorbet/tapioca/config.yml +26 -0
  145. data/sorbet/tapioca/extensions/load_gem.rb +1 -0
  146. data/sorbet/tapioca/require.rb +4 -0
  147. metadata +266 -0
@@ -0,0 +1,2289 @@
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+ is a \Hash object containing options
56
+ # that control both input 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
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+; specify +false+ to disable depth checking.
128
+ #
129
+ # With the default, +false+:
130
+ # source = '[0, [1, [2, [3]]]]'
131
+ # ruby = JSON.parse(source)
132
+ # ruby # => [0, [1, [2, [3]]]]
133
+ # Too deep:
134
+ # # Raises JSON::NestingError (nesting of 2 is too deep):
135
+ # JSON.parse(source, {max_nesting: 1})
136
+ # Bad value:
137
+ # # Raises TypeError (wrong argument type Symbol (expected Fixnum)):
138
+ # JSON.parse(source, {max_nesting: :foo})
139
+ #
140
+ # ---
141
+ #
142
+ # Option +allow_duplicate_key+ specifies whether duplicate keys in objects
143
+ # should be ignored or cause an error to be raised:
144
+ #
145
+ # When not specified:
146
+ # # The last value is used and a deprecation warning emitted.
147
+ # JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
148
+ # # warning: detected duplicate keys in JSON object.
149
+ # # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
150
+ #
151
+ # When set to +true+:
152
+ # # The last value is used.
153
+ # JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
154
+ #
155
+ # When set to +false+, the future default:
156
+ # JSON.parse('{"a": 1, "a":2}') => duplicate key at line 1 column 1 (JSON::ParserError)
157
+ #
158
+ # ---
159
+ #
160
+ # Option +allow_nan+ (boolean) specifies whether to allow
161
+ # NaN, Infinity, and MinusInfinity in +source+;
162
+ # defaults to +false+.
163
+ #
164
+ # With the default, +false+:
165
+ # # Raises JSON::ParserError (225: unexpected token at '[NaN]'):
166
+ # JSON.parse('[NaN]')
167
+ # # Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
168
+ # JSON.parse('[Infinity]')
169
+ # # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
170
+ # JSON.parse('[-Infinity]')
171
+ # Allow:
172
+ # source = '[NaN, Infinity, -Infinity]'
173
+ # ruby = JSON.parse(source, {allow_nan: true})
174
+ # ruby # => [NaN, Infinity, -Infinity]
175
+ #
176
+ # ---
177
+ #
178
+ # Option +allow_trailing_comma+ (boolean) specifies whether to allow
179
+ # trailing commas in objects and arrays;
180
+ # defaults to +false+.
181
+ #
182
+ # With the default, +false+:
183
+ # JSON.parse('[1,]') # unexpected character: ']' at line 1 column 4 (JSON::ParserError)
184
+ #
185
+ # When enabled:
186
+ # JSON.parse('[1,]', allow_trailing_comma: true) # => [1]
187
+ #
188
+ # ---
189
+ #
190
+ # Option +allow_comments+ (boolean) specifies whether to allow
191
+ # JavaScript style comments (either <tt>// comment</tt> or <tt>/* comment */</tt>);
192
+ # defaults to +false+.
193
+ #
194
+ # When not specified, a deprecation warning is emitted if a comment is encountered.
195
+ #
196
+ # When set to +true+, comments are ignored:
197
+ # JSON.parse('/* comment */ {"a": 1, "a":2}') # => {"a" => 2}
198
+ #
199
+ # When set to +false+, the future default:
200
+ # JSON.parse('/* comment */ {"a": 1, "a":2}') # unexpected character: '/' at line 1 column 1 (JSON::ParserError)
201
+ #
202
+ # ---
203
+ #
204
+ # Option +allow_control_characters+ (boolean) specifies whether to allow
205
+ # unescaped ASCII control characters, such as newlines, in strings;
206
+ # defaults to +false+.
207
+ #
208
+ # With the default, +false+:
209
+ # JSON.parse(%{"Hello\nWorld"}) # invalid ASCII control character in string (JSON::ParserError)
210
+ #
211
+ # When enabled:
212
+ # JSON.parse(%{"Hello\nWorld"}, allow_control_characters: true) # => "Hello\nWorld"
213
+ #
214
+ # ---
215
+ #
216
+ # Option +allow_invalid_escape+ (boolean) specifies whether to ignore backslahes that are followed
217
+ # by an invalid escape character in strings;
218
+ # defaults to +false+.
219
+ #
220
+ # With the default, +false+:
221
+ # JSON.parse('"Hell\o"') # invalid escape character in string (JSON::ParserError)
222
+ #
223
+ # When enabled:
224
+ # JSON.parse('"Hell\o"', allow_invalid_escape: true) # => "Hello"
225
+ #
226
+ # ====== Output Options
227
+ #
228
+ # Option +freeze+ (boolean) specifies whether the returned objects will be frozen;
229
+ # defaults to +false+.
230
+ #
231
+ # Option +symbolize_names+ (boolean) specifies whether returned \Hash keys
232
+ # should be Symbols;
233
+ # defaults to +false+ (use Strings).
234
+ #
235
+ # With the default, +false+:
236
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
237
+ # ruby = JSON.parse(source)
238
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
239
+ # Use Symbols:
240
+ # ruby = JSON.parse(source, {symbolize_names: true})
241
+ # ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
242
+ #
243
+ # ---
244
+ #
245
+ # Option +object_class+ (\Class) specifies the Ruby class to be used
246
+ # for each \JSON object;
247
+ # defaults to \Hash.
248
+ #
249
+ # With the default, \Hash:
250
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
251
+ # ruby = JSON.parse(source)
252
+ # ruby.class # => Hash
253
+ # Use class \OpenStruct:
254
+ # ruby = JSON.parse(source, {object_class: OpenStruct})
255
+ # ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
256
+ #
257
+ # ---
258
+ #
259
+ # Option +array_class+ (\Class) specifies the Ruby class to be used
260
+ # for each \JSON array;
261
+ # defaults to \Array.
262
+ #
263
+ # With the default, \Array:
264
+ # source = '["foo", 1.0, true, false, null]'
265
+ # ruby = JSON.parse(source)
266
+ # ruby.class # => Array
267
+ # Use class \Set:
268
+ # ruby = JSON.parse(source, {array_class: Set})
269
+ # ruby # => #<Set: {"foo", 1.0, true, false, nil}>
270
+ #
271
+ # ---
272
+ #
273
+ # Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing.
274
+ # See {\JSON Additions}[#module-JSON-label-JSON+Additions].
275
+ #
276
+ # === Generating \JSON
277
+ #
278
+ # To generate a Ruby \String containing \JSON data,
279
+ # use method <tt>JSON.generate(source, opts)</tt>, where
280
+ # - +source+ is a Ruby object.
281
+ # - +opts+ is a \Hash object containing options
282
+ # that control both input allowed and output formatting.
283
+ #
284
+ # ==== Generating \JSON from Arrays
285
+ #
286
+ # When the source is a Ruby \Array, JSON.generate returns
287
+ # a \String containing a \JSON array:
288
+ # ruby = [0, 's', :foo]
289
+ # json = JSON.generate(ruby)
290
+ # json # => '[0,"s","foo"]'
291
+ #
292
+ # The Ruby \Array array may contain nested arrays, hashes, and scalars
293
+ # to any depth:
294
+ # ruby = [0, [1, 2], {foo: 3, bar: 4}]
295
+ # json = JSON.generate(ruby)
296
+ # json # => '[0,[1,2],{"foo":3,"bar":4}]'
297
+ #
298
+ # ==== Generating \JSON from Hashes
299
+ #
300
+ # When the source is a Ruby \Hash, JSON.generate returns
301
+ # a \String containing a \JSON object:
302
+ # ruby = {foo: 0, bar: 's', baz: :bat}
303
+ # json = JSON.generate(ruby)
304
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
305
+ #
306
+ # The Ruby \Hash array may contain nested arrays, hashes, and scalars
307
+ # to any depth:
308
+ # ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
309
+ # json = JSON.generate(ruby)
310
+ # json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
311
+ #
312
+ # ==== Generating \JSON from Other Objects
313
+ #
314
+ # When the source is neither an \Array nor a \Hash,
315
+ # the generated \JSON data depends on the class of the source.
316
+ #
317
+ # When the source is a Ruby \Integer or \Float, JSON.generate returns
318
+ # a \String containing a \JSON number:
319
+ # JSON.generate(42) # => '42'
320
+ # JSON.generate(0.42) # => '0.42'
321
+ #
322
+ # When the source is a Ruby \String, JSON.generate returns
323
+ # a \String containing a \JSON string (with double-quotes):
324
+ # JSON.generate('A string') # => '"A string"'
325
+ #
326
+ # When the source is +true+, +false+ or +nil+, JSON.generate returns
327
+ # a \String containing the corresponding \JSON token:
328
+ # JSON.generate(true) # => 'true'
329
+ # JSON.generate(false) # => 'false'
330
+ # JSON.generate(nil) # => 'null'
331
+ #
332
+ # When the source is none of the above, JSON.generate returns
333
+ # a \String containing a \JSON string representation of the source:
334
+ # JSON.generate(:foo) # => '"foo"'
335
+ # JSON.generate(Complex(0, 0)) # => '"0+0i"'
336
+ # JSON.generate(Dir.new('.')) # => '"#<Dir>"'
337
+ #
338
+ # ==== Generating Options
339
+ #
340
+ # ====== Input Options
341
+ #
342
+ # Option +allow_nan+ (boolean) specifies whether
343
+ # +NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated;
344
+ # defaults to +false+.
345
+ #
346
+ # With the default, +false+:
347
+ # # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
348
+ # JSON.generate(JSON::NaN)
349
+ # # Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
350
+ # JSON.generate(JSON::Infinity)
351
+ # # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
352
+ # JSON.generate(JSON::MinusInfinity)
353
+ #
354
+ # Allow:
355
+ # ruby = [Float::NAN, Float::INFINITY, JSON::NaN, JSON::Infinity, JSON::MinusInfinity]
356
+ # JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,NaN,Infinity,-Infinity]'
357
+ #
358
+ # ---
359
+ #
360
+ # Option +allow_duplicate_key+ (boolean) specifies whether
361
+ # hashes with duplicate keys should be allowed or produce an error.
362
+ # defaults to emit a deprecation warning.
363
+ #
364
+ # With the default, (not set):
365
+ # Warning[:deprecated] = true
366
+ # JSON.generate({ foo: 1, "foo" => 2 })
367
+ # # warning: detected duplicate key "foo" in {foo: 1, "foo" => 2}.
368
+ # # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
369
+ # # => '{"foo":1,"foo":2}'
370
+ #
371
+ # With <tt>false</tt>
372
+ # JSON.generate({ foo: 1, "foo" => 2 }, allow_duplicate_key: false)
373
+ # # detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
374
+ #
375
+ # In version 3.0, <tt>false</tt> will become the default.
376
+ #
377
+ # ---
378
+ #
379
+ # Option +max_nesting+ (\Integer) specifies the maximum nesting depth
380
+ # in +obj+; defaults to +100+.
381
+ #
382
+ # With the default, +100+:
383
+ # obj = [[[[[[0]]]]]]
384
+ # JSON.generate(obj) # => '[[[[[[0]]]]]]'
385
+ #
386
+ # Too deep:
387
+ # # Raises JSON::NestingError (nesting of 2 is too deep):
388
+ # JSON.generate(obj, max_nesting: 2)
389
+ #
390
+ # ====== Escaping Options
391
+ #
392
+ # Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
393
+ # and <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script
394
+ # tags.
395
+ #
396
+ # Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range
397
+ # should be escaped.
398
+ #
399
+ # ====== Output Options
400
+ #
401
+ # The default formatting options generate the most compact
402
+ # \JSON data, all on one line and with no whitespace.
403
+ #
404
+ # You can use these formatting options to generate
405
+ # \JSON data in a more open format, using whitespace.
406
+ # See also JSON.pretty_generate.
407
+ #
408
+ # - Option +array_nl+ (\String) specifies a string (usually a newline)
409
+ # to be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>.
410
+ # - Option +object_nl+ (\String) specifies a string (usually a newline)
411
+ # to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
412
+ # - Option +indent+ (\String) specifies the string (usually spaces) to be
413
+ # used for indentation; defaults to the empty \String, <tt>''</tt>;
414
+ # has no effect unless options +array_nl+ or +object_nl+ specify newlines.
415
+ # - Option +space+ (\String) specifies a string (usually a space) to be
416
+ # inserted after the colon in each \JSON object's pair;
417
+ # defaults to the empty \String, <tt>''</tt>.
418
+ # - Option +space_before+ (\String) specifies a string (usually a space) to be
419
+ # inserted before the colon in each \JSON object's pair;
420
+ # defaults to the empty \String, <tt>''</tt>.
421
+ # - Option +sort_keys+ (boolean or \Proc) controls whether and how the keys of a
422
+ # hash are sorted when generating the output; defaults to <tt>false</tt>.
423
+ # When +true+, keys are sorted lexicographically. When a \Proc, it receives
424
+ # the entire \Hash and must return a \Hash with its pairs in the desired
425
+ # order, allowing for arbitrary sort orders.
426
+ #
427
+ # In this example, +obj+ is used first to generate the shortest
428
+ # \JSON data (no whitespace), then again with all formatting options
429
+ # specified:
430
+ #
431
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
432
+ # json = JSON.generate(obj)
433
+ # puts 'Compact:', json
434
+ # opts = {
435
+ # array_nl: "\n",
436
+ # object_nl: "\n",
437
+ # indent: ' ',
438
+ # space_before: ' ',
439
+ # space: ' '
440
+ # }
441
+ # puts 'Open:', JSON.generate(obj, opts)
442
+ #
443
+ # Output:
444
+ # Compact:
445
+ # {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
446
+ # Open:
447
+ # {
448
+ # "foo" : [
449
+ # "bar",
450
+ # "baz"
451
+ # ],
452
+ # "bat" : {
453
+ # "bam" : 0,
454
+ # "bad" : 1
455
+ # }
456
+ # }
457
+ #
458
+ # == \JSON Additions
459
+ #
460
+ # Note that JSON Additions must only be used with trusted data, and is
461
+ # deprecated.
462
+ #
463
+ # When you "round trip" a non-\String object from Ruby to \JSON and back,
464
+ # you have a new \String, instead of the object you began with:
465
+ # ruby0 = Range.new(0, 2)
466
+ # json = JSON.generate(ruby0)
467
+ # json # => '0..2"'
468
+ # ruby1 = JSON.parse(json)
469
+ # ruby1 # => '0..2'
470
+ # ruby1.class # => String
471
+ #
472
+ # You can use \JSON _additions_ to preserve the original object.
473
+ # The addition is an extension of a ruby class, so that:
474
+ # - \JSON.generate stores more information in the \JSON string.
475
+ # - \JSON.parse, called with option +create_additions+,
476
+ # uses that information to create a proper Ruby object.
477
+ #
478
+ # This example shows a \Range being generated into \JSON
479
+ # and parsed back into Ruby, both without and with
480
+ # the addition for \Range:
481
+ # ruby = Range.new(0, 2)
482
+ # # This passage does not use the addition for Range.
483
+ # json0 = JSON.generate(ruby)
484
+ # ruby0 = JSON.parse(json0)
485
+ # # This passage uses the addition for Range.
486
+ # require 'json/add/range'
487
+ # json1 = JSON.generate(ruby)
488
+ # ruby1 = JSON.parse(json1, create_additions: true)
489
+ # # Make a nice display.
490
+ # display = <<~EOT
491
+ # Generated JSON:
492
+ # Without addition: #{json0} (#{json0.class})
493
+ # With addition: #{json1} (#{json1.class})
494
+ # Parsed JSON:
495
+ # Without addition: #{ruby0.inspect} (#{ruby0.class})
496
+ # With addition: #{ruby1.inspect} (#{ruby1.class})
497
+ # EOT
498
+ # puts display
499
+ #
500
+ # This output shows the different results:
501
+ # Generated JSON:
502
+ # Without addition: "0..2" (String)
503
+ # With addition: {"json_class":"Range","a":[0,2,false]} (String)
504
+ # Parsed JSON:
505
+ # Without addition: "0..2" (String)
506
+ # With addition: 0..2 (Range)
507
+ #
508
+ # The \JSON module includes additions for certain classes.
509
+ # You can also craft custom additions.
510
+ # See {Custom \JSON Additions}[#module-JSON-label-Custom+JSON+Additions].
511
+ #
512
+ # === Built-in Additions
513
+ #
514
+ # The \JSON module includes additions for certain classes.
515
+ # To use an addition, +require+ its source:
516
+ # - BigDecimal: <tt>require 'json/add/bigdecimal'</tt>
517
+ # - Complex: <tt>require 'json/add/complex'</tt>
518
+ # - Date: <tt>require 'json/add/date'</tt>
519
+ # - DateTime: <tt>require 'json/add/date_time'</tt>
520
+ # - Exception: <tt>require 'json/add/exception'</tt>
521
+ # - OpenStruct: <tt>require 'json/add/ostruct'</tt>
522
+ # - Range: <tt>require 'json/add/range'</tt>
523
+ # - Rational: <tt>require 'json/add/rational'</tt>
524
+ # - Regexp: <tt>require 'json/add/regexp'</tt>
525
+ # - Set: <tt>require 'json/add/set'</tt>
526
+ # - Struct: <tt>require 'json/add/struct'</tt>
527
+ # - Symbol: <tt>require 'json/add/symbol'</tt>
528
+ # - Time: <tt>require 'json/add/time'</tt>
529
+ #
530
+ # To reduce punctuation clutter, the examples below
531
+ # show the generated \JSON via +puts+, rather than the usual +inspect+,
532
+ #
533
+ # \BigDecimal:
534
+ # require 'json/add/bigdecimal'
535
+ # ruby0 = BigDecimal(0) # 0.0
536
+ # json = JSON.generate(ruby0) # {"json_class":"BigDecimal","b":"27:0.0"}
537
+ # ruby1 = JSON.parse(json, create_additions: true) # 0.0
538
+ # ruby1.class # => BigDecimal
539
+ #
540
+ # \Complex:
541
+ # require 'json/add/complex'
542
+ # ruby0 = Complex(1+0i) # 1+0i
543
+ # json = JSON.generate(ruby0) # {"json_class":"Complex","r":1,"i":0}
544
+ # ruby1 = JSON.parse(json, create_additions: true) # 1+0i
545
+ # ruby1.class # Complex
546
+ #
547
+ # \Date:
548
+ # require 'json/add/date'
549
+ # ruby0 = Date.today # 2020-05-02
550
+ # json = JSON.generate(ruby0) # {"json_class":"Date","y":2020,"m":5,"d":2,"sg":2299161.0}
551
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02
552
+ # ruby1.class # Date
553
+ #
554
+ # \DateTime:
555
+ # require 'json/add/date_time'
556
+ # ruby0 = DateTime.now # 2020-05-02T10:38:13-05:00
557
+ # 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}
558
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02T10:38:13-05:00
559
+ # ruby1.class # DateTime
560
+ #
561
+ # \Exception (and its subclasses including \RuntimeError):
562
+ # require 'json/add/exception'
563
+ # ruby0 = Exception.new('A message') # A message
564
+ # json = JSON.generate(ruby0) # {"json_class":"Exception","m":"A message","b":null}
565
+ # ruby1 = JSON.parse(json, create_additions: true) # A message
566
+ # ruby1.class # Exception
567
+ # ruby0 = RuntimeError.new('Another message') # Another message
568
+ # json = JSON.generate(ruby0) # {"json_class":"RuntimeError","m":"Another message","b":null}
569
+ # ruby1 = JSON.parse(json, create_additions: true) # Another message
570
+ # ruby1.class # RuntimeError
571
+ #
572
+ # \OpenStruct:
573
+ # require 'json/add/ostruct'
574
+ # ruby0 = OpenStruct.new(name: 'Matz', language: 'Ruby') # #<OpenStruct name="Matz", language="Ruby">
575
+ # json = JSON.generate(ruby0) # {"json_class":"OpenStruct","t":{"name":"Matz","language":"Ruby"}}
576
+ # ruby1 = JSON.parse(json, create_additions: true) # #<OpenStruct name="Matz", language="Ruby">
577
+ # ruby1.class # OpenStruct
578
+ #
579
+ # \Range:
580
+ # require 'json/add/range'
581
+ # ruby0 = Range.new(0, 2) # 0..2
582
+ # json = JSON.generate(ruby0) # {"json_class":"Range","a":[0,2,false]}
583
+ # ruby1 = JSON.parse(json, create_additions: true) # 0..2
584
+ # ruby1.class # Range
585
+ #
586
+ # \Rational:
587
+ # require 'json/add/rational'
588
+ # ruby0 = Rational(1, 3) # 1/3
589
+ # json = JSON.generate(ruby0) # {"json_class":"Rational","n":1,"d":3}
590
+ # ruby1 = JSON.parse(json, create_additions: true) # 1/3
591
+ # ruby1.class # Rational
592
+ #
593
+ # \Regexp:
594
+ # require 'json/add/regexp'
595
+ # ruby0 = Regexp.new('foo') # (?-mix:foo)
596
+ # json = JSON.generate(ruby0) # {"json_class":"Regexp","o":0,"s":"foo"}
597
+ # ruby1 = JSON.parse(json, create_additions: true) # (?-mix:foo)
598
+ # ruby1.class # Regexp
599
+ #
600
+ # \Set:
601
+ # require 'json/add/set'
602
+ # ruby0 = Set.new([0, 1, 2]) # #<Set: {0, 1, 2}>
603
+ # json = JSON.generate(ruby0) # {"json_class":"Set","a":[0,1,2]}
604
+ # ruby1 = JSON.parse(json, create_additions: true) # #<Set: {0, 1, 2}>
605
+ # ruby1.class # Set
606
+ #
607
+ # \Struct:
608
+ # require 'json/add/struct'
609
+ # Customer = Struct.new(:name, :address) # Customer
610
+ # ruby0 = Customer.new("Dave", "123 Main") # #<struct Customer name="Dave", address="123 Main">
611
+ # json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
612
+ # ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
613
+ # ruby1.class # Customer
614
+ #
615
+ # \Symbol:
616
+ # require 'json/add/symbol'
617
+ # ruby0 = :foo # foo
618
+ # json = JSON.generate(ruby0) # {"json_class":"Symbol","s":"foo"}
619
+ # ruby1 = JSON.parse(json, create_additions: true) # foo
620
+ # ruby1.class # Symbol
621
+ #
622
+ # \Time:
623
+ # require 'json/add/time'
624
+ # ruby0 = Time.now # 2020-05-02 11:28:26 -0500
625
+ # json = JSON.generate(ruby0) # {"json_class":"Time","s":1588436906,"n":840560000}
626
+ # ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 11:28:26 -0500
627
+ # ruby1.class # Time
628
+ #
629
+ #
630
+ # === Custom \JSON Additions
631
+ #
632
+ # In addition to the \JSON additions provided,
633
+ # you can craft \JSON additions of your own,
634
+ # either for Ruby built-in classes or for user-defined classes.
635
+ #
636
+ # Here's a user-defined class +Foo+:
637
+ # class Foo
638
+ # attr_accessor :bar, :baz
639
+ # def initialize(bar, baz)
640
+ # self.bar = bar
641
+ # self.baz = baz
642
+ # end
643
+ # end
644
+ #
645
+ # Here's the \JSON addition for it:
646
+ # # Extend class Foo with JSON addition.
647
+ # class Foo
648
+ # # Serialize Foo object with its class name and arguments
649
+ # def to_json(*args)
650
+ # {
651
+ # JSON.create_id => self.class.name,
652
+ # 'a' => [ bar, baz ]
653
+ # }.to_json(*args)
654
+ # end
655
+ # # Deserialize JSON string by constructing new Foo object with arguments.
656
+ # def self.json_create(object)
657
+ # new(*object['a'])
658
+ # end
659
+ # end
660
+ #
661
+ # Demonstration:
662
+ # require 'json'
663
+ # # This Foo object has no custom addition.
664
+ # foo0 = Foo.new(0, 1)
665
+ # json0 = JSON.generate(foo0)
666
+ # obj0 = JSON.parse(json0)
667
+ # # Lood the custom addition.
668
+ # require_relative 'foo_addition'
669
+ # # This foo has the custom addition.
670
+ # foo1 = Foo.new(0, 1)
671
+ # json1 = JSON.generate(foo1)
672
+ # obj1 = JSON.parse(json1, create_additions: true)
673
+ # # Make a nice display.
674
+ # display = <<~EOT
675
+ # Generated JSON:
676
+ # Without custom addition: #{json0} (#{json0.class})
677
+ # With custom addition: #{json1} (#{json1.class})
678
+ # Parsed JSON:
679
+ # Without custom addition: #{obj0.inspect} (#{obj0.class})
680
+ # With custom addition: #{obj1.inspect} (#{obj1.class})
681
+ # EOT
682
+ # puts display
683
+ #
684
+ # Output:
685
+ #
686
+ # Generated JSON:
687
+ # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
688
+ # With custom addition: {"json_class":"Foo","a":[0,1]} (String)
689
+ # Parsed JSON:
690
+ # Without custom addition: "#<Foo:0x0000000006534e80>" (String)
691
+ # With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo)
692
+ #
693
+ # pkg:gem/json#lib/json/version.rb:3
694
+ module JSON
695
+ private
696
+
697
+ # :call-seq:
698
+ # JSON.dump(obj, io = nil, limit = nil)
699
+ #
700
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
701
+ #
702
+ # The default options can be changed via method JSON.dump_default_options.
703
+ #
704
+ # - Argument +io+, if given, should respond to method +write+;
705
+ # the \JSON \String is written to +io+, and +io+ is returned.
706
+ # If +io+ is not given, the \JSON \String is returned.
707
+ # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
708
+ #
709
+ # ---
710
+ #
711
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
712
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
713
+ # json = JSON.dump(obj)
714
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
715
+ #
716
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
717
+ # path = 't.json'
718
+ # File.open(path, 'w') do |file|
719
+ # JSON.dump(obj, file)
720
+ # end # => #<File:t.json (closed)>
721
+ # puts File.read(path)
722
+ # Output:
723
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
724
+ #
725
+ # pkg:gem/json#lib/json/common.rb:941
726
+ def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
727
+
728
+ # :call-seq:
729
+ # JSON.fast_generate(obj, opts) -> new_string
730
+ #
731
+ # Arguments +obj+ and +opts+ here are the same as
732
+ # arguments +obj+ and +opts+ in JSON.generate.
733
+ #
734
+ # By default, generates \JSON data without checking
735
+ # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
736
+ #
737
+ # Raises an exception if +obj+ contains circular references:
738
+ # a = []; b = []; a.push(b); b.push(a)
739
+ # # Raises SystemStackError (stack level too deep):
740
+ # JSON.fast_generate(a)
741
+ #
742
+ # pkg:gem/json#lib/json/common.rb:471
743
+ def fast_generate(obj, opts = T.unsafe(nil)); end
744
+
745
+ # pkg:gem/json#lib/json/common.rb:986
746
+ def fast_unparse(*_arg0, **_arg1, &_arg2); end
747
+
748
+ # :call-seq:
749
+ # JSON.generate(obj, opts = nil) -> new_string
750
+ #
751
+ # Returns a \String containing the generated \JSON data.
752
+ #
753
+ # See also JSON.pretty_generate.
754
+ #
755
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
756
+ #
757
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
758
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
759
+ #
760
+ # ---
761
+ #
762
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
763
+ # obj = ["foo", 1.0, true, false, nil]
764
+ # json = JSON.generate(obj)
765
+ # json # => '["foo",1.0,true,false,null]'
766
+ #
767
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
768
+ # obj = {foo: 0, bar: 's', baz: :bat}
769
+ # json = JSON.generate(obj)
770
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
771
+ #
772
+ # For examples of generating from other Ruby objects, see
773
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
774
+ #
775
+ # ---
776
+ #
777
+ # Raises an exception if any formatting option is not a \String.
778
+ #
779
+ # Raises an exception if +obj+ contains circular references:
780
+ # a = []; b = []; a.push(b); b.push(a)
781
+ # # Raises JSON::NestingError (nesting of 100 is too deep):
782
+ # JSON.generate(a)
783
+ #
784
+ # pkg:gem/json#lib/json/common.rb:450
785
+ def generate(obj, opts = T.unsafe(nil)); end
786
+
787
+ # :call-seq:
788
+ # JSON.load(source, options = {}) -> object
789
+ # JSON.load(source, proc = nil, options = {}) -> object
790
+ #
791
+ # Returns the Ruby objects created by parsing the given +source+.
792
+ #
793
+ # BEWARE: This method is meant to serialise data from trusted user input,
794
+ # like from your own database server or clients under your control, it could
795
+ # be dangerous to allow untrusted users to pass JSON sources into it.
796
+ # If you must use it, use JSON.unsafe_load instead to make it clear.
797
+ #
798
+ # Since JSON version 2.8.0, `load` emits a deprecation warning when a
799
+ # non native type is deserialized, without `create_additions` being explicitly
800
+ # enabled, and in JSON version 3.0, `load` will have `create_additions` disabled
801
+ # by default.
802
+ #
803
+ # - Argument +source+ must be, or be convertible to, a \String:
804
+ # - If +source+ responds to instance method +to_str+,
805
+ # <tt>source.to_str</tt> becomes the source.
806
+ # - If +source+ responds to instance method +to_io+,
807
+ # <tt>source.to_io.read</tt> becomes the source.
808
+ # - If +source+ responds to instance method +read+,
809
+ # <tt>source.read</tt> becomes the source.
810
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
811
+ # - Option +allow_blank+ specifies a truthy value.
812
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
813
+ # - Otherwise, +source+ remains the source.
814
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
815
+ # It will be called recursively with each result (depth-first order).
816
+ # See details below.
817
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
818
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
819
+ # The default options can be changed via method JSON.load_default_options=.
820
+ #
821
+ # ---
822
+ #
823
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
824
+ # <tt>parse(source, opts)</tt>; see #parse.
825
+ #
826
+ # Source for following examples:
827
+ # source = <<~JSON
828
+ # {
829
+ # "name": "Dave",
830
+ # "age" :40,
831
+ # "hats": [
832
+ # "Cattleman's",
833
+ # "Panama",
834
+ # "Tophat"
835
+ # ]
836
+ # }
837
+ # JSON
838
+ #
839
+ # Load a \String:
840
+ # ruby = JSON.load(source)
841
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
842
+ #
843
+ # Load an \IO object:
844
+ # require 'stringio'
845
+ # object = JSON.load(StringIO.new(source))
846
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
847
+ #
848
+ # Load a \File object:
849
+ # path = 't.json'
850
+ # File.write(path, source)
851
+ # File.open(path) do |file|
852
+ # JSON.load(file)
853
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
854
+ #
855
+ # ---
856
+ #
857
+ # When +proc+ is given:
858
+ # - Modifies +source+ as above.
859
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
860
+ # - Recursively calls <tt>proc(result)</tt>.
861
+ # - Returns the final result.
862
+ #
863
+ # Example:
864
+ # require 'json'
865
+ #
866
+ # # Some classes for the example.
867
+ # class Base
868
+ # def initialize(attributes)
869
+ # @attributes = attributes
870
+ # end
871
+ # end
872
+ # class User < Base; end
873
+ # class Account < Base; end
874
+ # class Admin < Base; end
875
+ # # The JSON source.
876
+ # json = <<-EOF
877
+ # {
878
+ # "users": [
879
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
880
+ # {"type": "User", "username": "john", "email": "john@example.com"}
881
+ # ],
882
+ # "accounts": [
883
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
884
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
885
+ # ],
886
+ # "admins": {"type": "Admin", "password": "0wn3d"}
887
+ # }
888
+ # EOF
889
+ # # Deserializer method.
890
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
891
+ # type = obj.is_a?(Hash) && obj["type"]
892
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
893
+ # end
894
+ # # Call to JSON.load
895
+ # ruby = JSON.load(json, proc {|obj|
896
+ # case obj
897
+ # when Hash
898
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
899
+ # when Array
900
+ # obj.map! {|v| deserialize_obj v }
901
+ # end
902
+ # obj
903
+ # })
904
+ # pp ruby
905
+ # Output:
906
+ # {"users"=>
907
+ # [#<User:0x00000000064c4c98
908
+ # @attributes=
909
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
910
+ # #<User:0x00000000064c4bd0
911
+ # @attributes=
912
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
913
+ # "accounts"=>
914
+ # [{"account"=>
915
+ # #<Account:0x00000000064c4928
916
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
917
+ # {"account"=>
918
+ # #<Account:0x00000000064c4680
919
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
920
+ # "admins"=>
921
+ # #<Admin:0x00000000064c41f8
922
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
923
+ #
924
+ # pkg:gem/json#lib/json/common.rb:865
925
+ def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
926
+
927
+ # :call-seq:
928
+ # JSON.load_file(path, opts={}) -> object
929
+ #
930
+ # Calls:
931
+ # parse(File.read(path), opts)
932
+ #
933
+ # See method #parse.
934
+ #
935
+ # pkg:gem/json#lib/json/common.rb:399
936
+ def load_file(filespec, opts = T.unsafe(nil)); end
937
+
938
+ # :call-seq:
939
+ # JSON.load_file!(path, opts = {})
940
+ #
941
+ # Calls:
942
+ # JSON.parse!(File.read(path, opts))
943
+ #
944
+ # See method #parse!
945
+ #
946
+ # pkg:gem/json#lib/json/common.rb:410
947
+ def load_file!(filespec, opts = T.unsafe(nil)); end
948
+
949
+ # :call-seq:
950
+ # JSON.parse(source, opts) -> object
951
+ #
952
+ # Returns the Ruby objects created by parsing the given +source+.
953
+ #
954
+ # Argument +source+ contains the \String to be parsed.
955
+ #
956
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
957
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
958
+ #
959
+ # ---
960
+ #
961
+ # When +source+ is a \JSON array, returns a Ruby \Array:
962
+ # source = '["foo", 1.0, true, false, null]'
963
+ # ruby = JSON.parse(source)
964
+ # ruby # => ["foo", 1.0, true, false, nil]
965
+ # ruby.class # => Array
966
+ #
967
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
968
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
969
+ # ruby = JSON.parse(source)
970
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
971
+ # ruby.class # => Hash
972
+ #
973
+ # For examples of parsing for all \JSON data types, see
974
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
975
+ #
976
+ # Parses nested JSON objects:
977
+ # source = <<~JSON
978
+ # {
979
+ # "name": "Dave",
980
+ # "age" :40,
981
+ # "hats": [
982
+ # "Cattleman's",
983
+ # "Panama",
984
+ # "Tophat"
985
+ # ]
986
+ # }
987
+ # JSON
988
+ # ruby = JSON.parse(source)
989
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
990
+ #
991
+ # ---
992
+ #
993
+ # Raises an exception if +source+ is not valid JSON:
994
+ # # Raises JSON::ParserError (783: unexpected token at ''):
995
+ # JSON.parse('')
996
+ #
997
+ # pkg:gem/json#lib/json/common.rb:362
998
+ def parse(source, opts = T.unsafe(nil)); end
999
+
1000
+ # :call-seq:
1001
+ # JSON.parse!(source, opts) -> object
1002
+ #
1003
+ # Calls
1004
+ # parse(source, opts)
1005
+ # with +source+ and possibly modified +opts+.
1006
+ #
1007
+ # Differences from JSON.parse:
1008
+ # - Option +max_nesting+, if not provided, defaults to +false+,
1009
+ # which disables checking for nesting depth.
1010
+ # - Option +allow_nan+, if not provided, defaults to +true+.
1011
+ #
1012
+ # pkg:gem/json#lib/json/common.rb:384
1013
+ def parse!(source, opts = T.unsafe(nil)); end
1014
+
1015
+ # :call-seq:
1016
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
1017
+ #
1018
+ # Arguments +obj+ and +opts+ here are the same as
1019
+ # arguments +obj+ and +opts+ in JSON.generate.
1020
+ #
1021
+ # Default options are:
1022
+ # {
1023
+ # indent: ' ', # Two spaces
1024
+ # space: ' ', # One space
1025
+ # array_nl: "\n", # Newline
1026
+ # object_nl: "\n" # Newline
1027
+ # }
1028
+ #
1029
+ # Example:
1030
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
1031
+ # json = JSON.pretty_generate(obj)
1032
+ # puts json
1033
+ # Output:
1034
+ # {
1035
+ # "foo": [
1036
+ # "bar",
1037
+ # "baz"
1038
+ # ],
1039
+ # "bat": {
1040
+ # "bam": 0,
1041
+ # "bad": 1
1042
+ # }
1043
+ # }
1044
+ #
1045
+ # pkg:gem/json#lib/json/common.rb:518
1046
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
1047
+
1048
+ # pkg:gem/json#lib/json/common.rb:996
1049
+ def pretty_unparse(*_arg0, **_arg1, &_arg2); end
1050
+
1051
+ # pkg:gem/json#lib/json/common.rb:1006
1052
+ def restore(*_arg0, **_arg1, &_arg2); end
1053
+
1054
+ # :stopdoc:
1055
+ # All these were meant to be deprecated circa 2009, but were just set as undocumented
1056
+ # so usage still exist in the wild.
1057
+ #
1058
+ # pkg:gem/json#lib/json/common.rb:976
1059
+ def unparse(*_arg0, **_arg1, &_arg2); end
1060
+
1061
+ # :call-seq:
1062
+ # JSON.unsafe_load(source, options = {}) -> object
1063
+ # JSON.unsafe_load(source, proc = nil, options = {}) -> object
1064
+ #
1065
+ # Returns the Ruby objects created by parsing the given +source+.
1066
+ #
1067
+ # BEWARE: This method is meant to serialise data from trusted user input,
1068
+ # like from your own database server or clients under your control, it could
1069
+ # be dangerous to allow untrusted users to pass JSON sources into it.
1070
+ #
1071
+ # - Argument +source+ must be, or be convertible to, a \String:
1072
+ # - If +source+ responds to instance method +to_str+,
1073
+ # <tt>source.to_str</tt> becomes the source.
1074
+ # - If +source+ responds to instance method +to_io+,
1075
+ # <tt>source.to_io.read</tt> becomes the source.
1076
+ # - If +source+ responds to instance method +read+,
1077
+ # <tt>source.read</tt> becomes the source.
1078
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1079
+ # - Option +allow_blank+ specifies a truthy value.
1080
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1081
+ # - Otherwise, +source+ remains the source.
1082
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1083
+ # It will be called recursively with each result (depth-first order).
1084
+ # See details below.
1085
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1086
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1087
+ # The default options can be changed via method JSON.unsafe_load_default_options=.
1088
+ #
1089
+ # ---
1090
+ #
1091
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
1092
+ # <tt>parse(source, opts)</tt>; see #parse.
1093
+ #
1094
+ # Source for following examples:
1095
+ # source = <<~JSON
1096
+ # {
1097
+ # "name": "Dave",
1098
+ # "age" :40,
1099
+ # "hats": [
1100
+ # "Cattleman's",
1101
+ # "Panama",
1102
+ # "Tophat"
1103
+ # ]
1104
+ # }
1105
+ # JSON
1106
+ #
1107
+ # Load a \String:
1108
+ # ruby = JSON.unsafe_load(source)
1109
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1110
+ #
1111
+ # Load an \IO object:
1112
+ # require 'stringio'
1113
+ # object = JSON.unsafe_load(StringIO.new(source))
1114
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1115
+ #
1116
+ # Load a \File object:
1117
+ # path = 't.json'
1118
+ # File.write(path, source)
1119
+ # File.open(path) do |file|
1120
+ # JSON.unsafe_load(file)
1121
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1122
+ #
1123
+ # ---
1124
+ #
1125
+ # When +proc+ is given:
1126
+ # - Modifies +source+ as above.
1127
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1128
+ # - Recursively calls <tt>proc(result)</tt>.
1129
+ # - Returns the final result.
1130
+ #
1131
+ # Example:
1132
+ # require 'json'
1133
+ #
1134
+ # # Some classes for the example.
1135
+ # class Base
1136
+ # def initialize(attributes)
1137
+ # @attributes = attributes
1138
+ # end
1139
+ # end
1140
+ # class User < Base; end
1141
+ # class Account < Base; end
1142
+ # class Admin < Base; end
1143
+ # # The JSON source.
1144
+ # json = <<-EOF
1145
+ # {
1146
+ # "users": [
1147
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
1148
+ # {"type": "User", "username": "john", "email": "john@example.com"}
1149
+ # ],
1150
+ # "accounts": [
1151
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1152
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1153
+ # ],
1154
+ # "admins": {"type": "Admin", "password": "0wn3d"}
1155
+ # }
1156
+ # EOF
1157
+ # # Deserializer method.
1158
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1159
+ # type = obj.is_a?(Hash) && obj["type"]
1160
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1161
+ # end
1162
+ # # Call to JSON.unsafe_load
1163
+ # ruby = JSON.unsafe_load(json, proc {|obj|
1164
+ # case obj
1165
+ # when Hash
1166
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
1167
+ # when Array
1168
+ # obj.map! {|v| deserialize_obj v }
1169
+ # end
1170
+ # obj
1171
+ # })
1172
+ # pp ruby
1173
+ # Output:
1174
+ # {"users"=>
1175
+ # [#<User:0x00000000064c4c98
1176
+ # @attributes=
1177
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1178
+ # #<User:0x00000000064c4bd0
1179
+ # @attributes=
1180
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1181
+ # "accounts"=>
1182
+ # [{"account"=>
1183
+ # #<Account:0x00000000064c4928
1184
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1185
+ # {"account"=>
1186
+ # #<Account:0x00000000064c4680
1187
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1188
+ # "admins"=>
1189
+ # #<Admin:0x00000000064c41f8
1190
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1191
+ #
1192
+ # pkg:gem/json#lib/json/common.rb:694
1193
+ def unsafe_load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1194
+
1195
+ class << self
1196
+ # :call-seq:
1197
+ # JSON[object] -> new_array or new_string
1198
+ #
1199
+ # If +object+ is a \String,
1200
+ # calls JSON.parse with +object+ and +opts+ (see method #parse):
1201
+ # json = '[0, 1, null]'
1202
+ # JSON[json]# => [0, 1, nil]
1203
+ #
1204
+ # Otherwise, calls JSON.generate with +object+ and +opts+ (see method #generate):
1205
+ # ruby = [0, 1, nil]
1206
+ # JSON[ruby] # => '[0,1,null]'
1207
+ #
1208
+ # pkg:gem/json#lib/json/common.rb:132
1209
+ def [](object, opts = T.unsafe(nil)); end
1210
+
1211
+ # pkg:gem/json#lib/json/common.rb:217
1212
+ def _dump_default_options; end
1213
+
1214
+ # pkg:gem/json#lib/json/common.rb:217
1215
+ def _load_default_options; end
1216
+
1217
+ # pkg:gem/json#lib/json/common.rb:217
1218
+ def _unsafe_load_default_options; end
1219
+
1220
+ # Returns the current create identifier.
1221
+ # See also JSON.create_id=.
1222
+ #
1223
+ # pkg:gem/json#lib/json/common.rb:245
1224
+ def create_id; end
1225
+
1226
+ # Sets create identifier, which is used to decide if the _json_create_
1227
+ # hook of a class should be called; initial value is +json_class+:
1228
+ # JSON.create_id # => 'json_class'
1229
+ #
1230
+ # pkg:gem/json#lib/json/common.rb:239
1231
+ def create_id=(new_value); end
1232
+
1233
+ # pkg:gem/json#lib/json/common.rb:104
1234
+ def deprecation_warning(message, uplevel = T.unsafe(nil)); end
1235
+
1236
+ # :call-seq:
1237
+ # JSON.dump(obj, io = nil, limit = nil)
1238
+ #
1239
+ # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
1240
+ #
1241
+ # The default options can be changed via method JSON.dump_default_options.
1242
+ #
1243
+ # - Argument +io+, if given, should respond to method +write+;
1244
+ # the \JSON \String is written to +io+, and +io+ is returned.
1245
+ # If +io+ is not given, the \JSON \String is returned.
1246
+ # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
1247
+ #
1248
+ # ---
1249
+ #
1250
+ # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
1251
+ # obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
1252
+ # json = JSON.dump(obj)
1253
+ # json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
1254
+ #
1255
+ # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
1256
+ # path = 't.json'
1257
+ # File.open(path, 'w') do |file|
1258
+ # JSON.dump(obj, file)
1259
+ # end # => #<File:t.json (closed)>
1260
+ # puts File.read(path)
1261
+ # Output:
1262
+ # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
1263
+ #
1264
+ # pkg:gem/json#lib/json/common.rb:941
1265
+ def dump(obj, anIO = T.unsafe(nil), limit = T.unsafe(nil), kwargs = T.unsafe(nil)); end
1266
+
1267
+ # pkg:gem/json#lib/json/common.rb:217
1268
+ def dump_default_options; end
1269
+
1270
+ # pkg:gem/json#lib/json/common.rb:217
1271
+ def dump_default_options=(val); end
1272
+
1273
+ # :call-seq:
1274
+ # JSON.fast_generate(obj, opts) -> new_string
1275
+ #
1276
+ # Arguments +obj+ and +opts+ here are the same as
1277
+ # arguments +obj+ and +opts+ in JSON.generate.
1278
+ #
1279
+ # By default, generates \JSON data without checking
1280
+ # for circular references in +obj+ (option +max_nesting+ set to +false+, disabled).
1281
+ #
1282
+ # Raises an exception if +obj+ contains circular references:
1283
+ # a = []; b = []; a.push(b); b.push(a)
1284
+ # # Raises SystemStackError (stack level too deep):
1285
+ # JSON.fast_generate(a)
1286
+ #
1287
+ # pkg:gem/json#lib/json/common.rb:471
1288
+ def fast_generate(obj, opts = T.unsafe(nil)); end
1289
+
1290
+ # pkg:gem/json#lib/json/common.rb:986
1291
+ def fast_unparse(*_arg0, **_arg1, &_arg2); end
1292
+
1293
+ # :call-seq:
1294
+ # JSON.generate(obj, opts = nil) -> new_string
1295
+ #
1296
+ # Returns a \String containing the generated \JSON data.
1297
+ #
1298
+ # See also JSON.pretty_generate.
1299
+ #
1300
+ # Argument +obj+ is the Ruby object to be converted to \JSON.
1301
+ #
1302
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
1303
+ # See {Generating Options}[#module-JSON-label-Generating+Options].
1304
+ #
1305
+ # ---
1306
+ #
1307
+ # When +obj+ is an \Array, returns a \String containing a \JSON array:
1308
+ # obj = ["foo", 1.0, true, false, nil]
1309
+ # json = JSON.generate(obj)
1310
+ # json # => '["foo",1.0,true,false,null]'
1311
+ #
1312
+ # When +obj+ is a \Hash, returns a \String containing a \JSON object:
1313
+ # obj = {foo: 0, bar: 's', baz: :bat}
1314
+ # json = JSON.generate(obj)
1315
+ # json # => '{"foo":0,"bar":"s","baz":"bat"}'
1316
+ #
1317
+ # For examples of generating from other Ruby objects, see
1318
+ # {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
1319
+ #
1320
+ # ---
1321
+ #
1322
+ # Raises an exception if any formatting option is not a \String.
1323
+ #
1324
+ # Raises an exception if +obj+ contains circular references:
1325
+ # a = []; b = []; a.push(b); b.push(a)
1326
+ # # Raises JSON::NestingError (nesting of 100 is too deep):
1327
+ # JSON.generate(a)
1328
+ #
1329
+ # pkg:gem/json#lib/json/common.rb:450
1330
+ def generate(obj, opts = T.unsafe(nil)); end
1331
+
1332
+ # Returns the JSON generator module that is used by JSON.
1333
+ #
1334
+ # pkg:gem/json#lib/json/common.rb:188
1335
+ def generator; end
1336
+
1337
+ # Set the module _generator_ to be used by JSON.
1338
+ #
1339
+ # pkg:gem/json#lib/json/common.rb:156
1340
+ def generator=(generator); end
1341
+
1342
+ # :call-seq:
1343
+ # JSON.load(source, options = {}) -> object
1344
+ # JSON.load(source, proc = nil, options = {}) -> object
1345
+ #
1346
+ # Returns the Ruby objects created by parsing the given +source+.
1347
+ #
1348
+ # BEWARE: This method is meant to serialise data from trusted user input,
1349
+ # like from your own database server or clients under your control, it could
1350
+ # be dangerous to allow untrusted users to pass JSON sources into it.
1351
+ # If you must use it, use JSON.unsafe_load instead to make it clear.
1352
+ #
1353
+ # Since JSON version 2.8.0, `load` emits a deprecation warning when a
1354
+ # non native type is deserialized, without `create_additions` being explicitly
1355
+ # enabled, and in JSON version 3.0, `load` will have `create_additions` disabled
1356
+ # by default.
1357
+ #
1358
+ # - Argument +source+ must be, or be convertible to, a \String:
1359
+ # - If +source+ responds to instance method +to_str+,
1360
+ # <tt>source.to_str</tt> becomes the source.
1361
+ # - If +source+ responds to instance method +to_io+,
1362
+ # <tt>source.to_io.read</tt> becomes the source.
1363
+ # - If +source+ responds to instance method +read+,
1364
+ # <tt>source.read</tt> becomes the source.
1365
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1366
+ # - Option +allow_blank+ specifies a truthy value.
1367
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1368
+ # - Otherwise, +source+ remains the source.
1369
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1370
+ # It will be called recursively with each result (depth-first order).
1371
+ # See details below.
1372
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1373
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1374
+ # The default options can be changed via method JSON.load_default_options=.
1375
+ #
1376
+ # ---
1377
+ #
1378
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
1379
+ # <tt>parse(source, opts)</tt>; see #parse.
1380
+ #
1381
+ # Source for following examples:
1382
+ # source = <<~JSON
1383
+ # {
1384
+ # "name": "Dave",
1385
+ # "age" :40,
1386
+ # "hats": [
1387
+ # "Cattleman's",
1388
+ # "Panama",
1389
+ # "Tophat"
1390
+ # ]
1391
+ # }
1392
+ # JSON
1393
+ #
1394
+ # Load a \String:
1395
+ # ruby = JSON.load(source)
1396
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1397
+ #
1398
+ # Load an \IO object:
1399
+ # require 'stringio'
1400
+ # object = JSON.load(StringIO.new(source))
1401
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1402
+ #
1403
+ # Load a \File object:
1404
+ # path = 't.json'
1405
+ # File.write(path, source)
1406
+ # File.open(path) do |file|
1407
+ # JSON.load(file)
1408
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1409
+ #
1410
+ # ---
1411
+ #
1412
+ # When +proc+ is given:
1413
+ # - Modifies +source+ as above.
1414
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1415
+ # - Recursively calls <tt>proc(result)</tt>.
1416
+ # - Returns the final result.
1417
+ #
1418
+ # Example:
1419
+ # require 'json'
1420
+ #
1421
+ # # Some classes for the example.
1422
+ # class Base
1423
+ # def initialize(attributes)
1424
+ # @attributes = attributes
1425
+ # end
1426
+ # end
1427
+ # class User < Base; end
1428
+ # class Account < Base; end
1429
+ # class Admin < Base; end
1430
+ # # The JSON source.
1431
+ # json = <<-EOF
1432
+ # {
1433
+ # "users": [
1434
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
1435
+ # {"type": "User", "username": "john", "email": "john@example.com"}
1436
+ # ],
1437
+ # "accounts": [
1438
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1439
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1440
+ # ],
1441
+ # "admins": {"type": "Admin", "password": "0wn3d"}
1442
+ # }
1443
+ # EOF
1444
+ # # Deserializer method.
1445
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1446
+ # type = obj.is_a?(Hash) && obj["type"]
1447
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1448
+ # end
1449
+ # # Call to JSON.load
1450
+ # ruby = JSON.load(json, proc {|obj|
1451
+ # case obj
1452
+ # when Hash
1453
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
1454
+ # when Array
1455
+ # obj.map! {|v| deserialize_obj v }
1456
+ # end
1457
+ # obj
1458
+ # })
1459
+ # pp ruby
1460
+ # Output:
1461
+ # {"users"=>
1462
+ # [#<User:0x00000000064c4c98
1463
+ # @attributes=
1464
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1465
+ # #<User:0x00000000064c4bd0
1466
+ # @attributes=
1467
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1468
+ # "accounts"=>
1469
+ # [{"account"=>
1470
+ # #<Account:0x00000000064c4928
1471
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1472
+ # {"account"=>
1473
+ # #<Account:0x00000000064c4680
1474
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1475
+ # "admins"=>
1476
+ # #<Admin:0x00000000064c41f8
1477
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1478
+ #
1479
+ # pkg:gem/json#lib/json/common.rb:865
1480
+ def load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1481
+
1482
+ # pkg:gem/json#lib/json/common.rb:217
1483
+ def load_default_options; end
1484
+
1485
+ # pkg:gem/json#lib/json/common.rb:217
1486
+ def load_default_options=(val); end
1487
+
1488
+ # :call-seq:
1489
+ # JSON.load_file(path, opts={}) -> object
1490
+ #
1491
+ # Calls:
1492
+ # parse(File.read(path), opts)
1493
+ #
1494
+ # See method #parse.
1495
+ #
1496
+ # pkg:gem/json#lib/json/common.rb:399
1497
+ def load_file(filespec, opts = T.unsafe(nil)); end
1498
+
1499
+ # :call-seq:
1500
+ # JSON.load_file!(path, opts = {})
1501
+ #
1502
+ # Calls:
1503
+ # JSON.parse!(File.read(path, opts))
1504
+ #
1505
+ # See method #parse!
1506
+ #
1507
+ # pkg:gem/json#lib/json/common.rb:410
1508
+ def load_file!(filespec, opts = T.unsafe(nil)); end
1509
+
1510
+ # :call-seq:
1511
+ # JSON.parse(source, opts) -> object
1512
+ #
1513
+ # Returns the Ruby objects created by parsing the given +source+.
1514
+ #
1515
+ # Argument +source+ contains the \String to be parsed.
1516
+ #
1517
+ # Argument +opts+, if given, contains a \Hash of options for the parsing.
1518
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1519
+ #
1520
+ # ---
1521
+ #
1522
+ # When +source+ is a \JSON array, returns a Ruby \Array:
1523
+ # source = '["foo", 1.0, true, false, null]'
1524
+ # ruby = JSON.parse(source)
1525
+ # ruby # => ["foo", 1.0, true, false, nil]
1526
+ # ruby.class # => Array
1527
+ #
1528
+ # When +source+ is a \JSON object, returns a Ruby \Hash:
1529
+ # source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
1530
+ # ruby = JSON.parse(source)
1531
+ # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
1532
+ # ruby.class # => Hash
1533
+ #
1534
+ # For examples of parsing for all \JSON data types, see
1535
+ # {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
1536
+ #
1537
+ # Parses nested JSON objects:
1538
+ # source = <<~JSON
1539
+ # {
1540
+ # "name": "Dave",
1541
+ # "age" :40,
1542
+ # "hats": [
1543
+ # "Cattleman's",
1544
+ # "Panama",
1545
+ # "Tophat"
1546
+ # ]
1547
+ # }
1548
+ # JSON
1549
+ # ruby = JSON.parse(source)
1550
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1551
+ #
1552
+ # ---
1553
+ #
1554
+ # Raises an exception if +source+ is not valid JSON:
1555
+ # # Raises JSON::ParserError (783: unexpected token at ''):
1556
+ # JSON.parse('')
1557
+ #
1558
+ # pkg:gem/json#lib/json/common.rb:362
1559
+ def parse(source, opts = T.unsafe(nil)); end
1560
+
1561
+ # :call-seq:
1562
+ # JSON.parse!(source, opts) -> object
1563
+ #
1564
+ # Calls
1565
+ # parse(source, opts)
1566
+ # with +source+ and possibly modified +opts+.
1567
+ #
1568
+ # Differences from JSON.parse:
1569
+ # - Option +max_nesting+, if not provided, defaults to +false+,
1570
+ # which disables checking for nesting depth.
1571
+ # - Option +allow_nan+, if not provided, defaults to +true+.
1572
+ #
1573
+ # pkg:gem/json#lib/json/common.rb:384
1574
+ def parse!(source, opts = T.unsafe(nil)); end
1575
+
1576
+ # Returns the JSON parser class that is used by JSON.
1577
+ #
1578
+ # pkg:gem/json#lib/json/common.rb:146
1579
+ def parser; end
1580
+
1581
+ # Set the JSON parser class _parser_ to be used by JSON.
1582
+ #
1583
+ # pkg:gem/json#lib/json/common.rb:149
1584
+ def parser=(parser); end
1585
+
1586
+ # :call-seq:
1587
+ # JSON.pretty_generate(obj, opts = nil) -> new_string
1588
+ #
1589
+ # Arguments +obj+ and +opts+ here are the same as
1590
+ # arguments +obj+ and +opts+ in JSON.generate.
1591
+ #
1592
+ # Default options are:
1593
+ # {
1594
+ # indent: ' ', # Two spaces
1595
+ # space: ' ', # One space
1596
+ # array_nl: "\n", # Newline
1597
+ # object_nl: "\n" # Newline
1598
+ # }
1599
+ #
1600
+ # Example:
1601
+ # obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
1602
+ # json = JSON.pretty_generate(obj)
1603
+ # puts json
1604
+ # Output:
1605
+ # {
1606
+ # "foo": [
1607
+ # "bar",
1608
+ # "baz"
1609
+ # ],
1610
+ # "bat": {
1611
+ # "bam": 0,
1612
+ # "bad": 1
1613
+ # }
1614
+ # }
1615
+ #
1616
+ # pkg:gem/json#lib/json/common.rb:518
1617
+ def pretty_generate(obj, opts = T.unsafe(nil)); end
1618
+
1619
+ # pkg:gem/json#lib/json/common.rb:996
1620
+ def pretty_unparse(*_arg0, **_arg1, &_arg2); end
1621
+
1622
+ # pkg:gem/json#lib/json/common.rb:1006
1623
+ def restore(*_arg0, **_arg1, &_arg2); end
1624
+
1625
+ # Sets or Returns the JSON generator state class that is used by JSON.
1626
+ #
1627
+ # pkg:gem/json#lib/json/common.rb:191
1628
+ def state; end
1629
+
1630
+ # Sets or Returns the JSON generator state class that is used by JSON.
1631
+ #
1632
+ # pkg:gem/json#lib/json/common.rb:191
1633
+ def state=(_arg0); end
1634
+
1635
+ # :stopdoc:
1636
+ # All these were meant to be deprecated circa 2009, but were just set as undocumented
1637
+ # so usage still exist in the wild.
1638
+ #
1639
+ # pkg:gem/json#lib/json/common.rb:976
1640
+ def unparse(*_arg0, **_arg1, &_arg2); end
1641
+
1642
+ # :call-seq:
1643
+ # JSON.unsafe_load(source, options = {}) -> object
1644
+ # JSON.unsafe_load(source, proc = nil, options = {}) -> object
1645
+ #
1646
+ # Returns the Ruby objects created by parsing the given +source+.
1647
+ #
1648
+ # BEWARE: This method is meant to serialise data from trusted user input,
1649
+ # like from your own database server or clients under your control, it could
1650
+ # be dangerous to allow untrusted users to pass JSON sources into it.
1651
+ #
1652
+ # - Argument +source+ must be, or be convertible to, a \String:
1653
+ # - If +source+ responds to instance method +to_str+,
1654
+ # <tt>source.to_str</tt> becomes the source.
1655
+ # - If +source+ responds to instance method +to_io+,
1656
+ # <tt>source.to_io.read</tt> becomes the source.
1657
+ # - If +source+ responds to instance method +read+,
1658
+ # <tt>source.read</tt> becomes the source.
1659
+ # - If both of the following are true, source becomes the \String <tt>'null'</tt>:
1660
+ # - Option +allow_blank+ specifies a truthy value.
1661
+ # - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>.
1662
+ # - Otherwise, +source+ remains the source.
1663
+ # - Argument +proc+, if given, must be a \Proc that accepts one argument.
1664
+ # It will be called recursively with each result (depth-first order).
1665
+ # See details below.
1666
+ # - Argument +opts+, if given, contains a \Hash of options for the parsing.
1667
+ # See {Parsing Options}[#module-JSON-label-Parsing+Options].
1668
+ # The default options can be changed via method JSON.unsafe_load_default_options=.
1669
+ #
1670
+ # ---
1671
+ #
1672
+ # When no +proc+ is given, modifies +source+ as above and returns the result of
1673
+ # <tt>parse(source, opts)</tt>; see #parse.
1674
+ #
1675
+ # Source for following examples:
1676
+ # source = <<~JSON
1677
+ # {
1678
+ # "name": "Dave",
1679
+ # "age" :40,
1680
+ # "hats": [
1681
+ # "Cattleman's",
1682
+ # "Panama",
1683
+ # "Tophat"
1684
+ # ]
1685
+ # }
1686
+ # JSON
1687
+ #
1688
+ # Load a \String:
1689
+ # ruby = JSON.unsafe_load(source)
1690
+ # ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1691
+ #
1692
+ # Load an \IO object:
1693
+ # require 'stringio'
1694
+ # object = JSON.unsafe_load(StringIO.new(source))
1695
+ # object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1696
+ #
1697
+ # Load a \File object:
1698
+ # path = 't.json'
1699
+ # File.write(path, source)
1700
+ # File.open(path) do |file|
1701
+ # JSON.unsafe_load(file)
1702
+ # end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
1703
+ #
1704
+ # ---
1705
+ #
1706
+ # When +proc+ is given:
1707
+ # - Modifies +source+ as above.
1708
+ # - Gets the +result+ from calling <tt>parse(source, opts)</tt>.
1709
+ # - Recursively calls <tt>proc(result)</tt>.
1710
+ # - Returns the final result.
1711
+ #
1712
+ # Example:
1713
+ # require 'json'
1714
+ #
1715
+ # # Some classes for the example.
1716
+ # class Base
1717
+ # def initialize(attributes)
1718
+ # @attributes = attributes
1719
+ # end
1720
+ # end
1721
+ # class User < Base; end
1722
+ # class Account < Base; end
1723
+ # class Admin < Base; end
1724
+ # # The JSON source.
1725
+ # json = <<-EOF
1726
+ # {
1727
+ # "users": [
1728
+ # {"type": "User", "username": "jane", "email": "jane@example.com"},
1729
+ # {"type": "User", "username": "john", "email": "john@example.com"}
1730
+ # ],
1731
+ # "accounts": [
1732
+ # {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
1733
+ # {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
1734
+ # ],
1735
+ # "admins": {"type": "Admin", "password": "0wn3d"}
1736
+ # }
1737
+ # EOF
1738
+ # # Deserializer method.
1739
+ # def deserialize_obj(obj, safe_types = %w(User Account Admin))
1740
+ # type = obj.is_a?(Hash) && obj["type"]
1741
+ # safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
1742
+ # end
1743
+ # # Call to JSON.unsafe_load
1744
+ # ruby = JSON.unsafe_load(json, proc {|obj|
1745
+ # case obj
1746
+ # when Hash
1747
+ # obj.each {|k, v| obj[k] = deserialize_obj v }
1748
+ # when Array
1749
+ # obj.map! {|v| deserialize_obj v }
1750
+ # end
1751
+ # obj
1752
+ # })
1753
+ # pp ruby
1754
+ # Output:
1755
+ # {"users"=>
1756
+ # [#<User:0x00000000064c4c98
1757
+ # @attributes=
1758
+ # {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
1759
+ # #<User:0x00000000064c4bd0
1760
+ # @attributes=
1761
+ # {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
1762
+ # "accounts"=>
1763
+ # [{"account"=>
1764
+ # #<Account:0x00000000064c4928
1765
+ # @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
1766
+ # {"account"=>
1767
+ # #<Account:0x00000000064c4680
1768
+ # @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
1769
+ # "admins"=>
1770
+ # #<Admin:0x00000000064c41f8
1771
+ # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
1772
+ #
1773
+ # pkg:gem/json#lib/json/common.rb:694
1774
+ def unsafe_load(source, proc = T.unsafe(nil), options = T.unsafe(nil)); end
1775
+
1776
+ # pkg:gem/json#lib/json/common.rb:217
1777
+ def unsafe_load_default_options; end
1778
+
1779
+ # pkg:gem/json#lib/json/common.rb:217
1780
+ def unsafe_load_default_options=(val); end
1781
+
1782
+ private
1783
+
1784
+ # pkg:gem/json#lib/json/common.rb:1019
1785
+ def const_missing(const_name); end
1786
+
1787
+ # pkg:gem/json#lib/json/common.rb:214
1788
+ def deprecated_singleton_attr_accessor(*attrs); end
1789
+
1790
+ # Called from the extension when a hash has both string and symbol keys
1791
+ #
1792
+ # pkg:gem/json#lib/json/common.rb:196
1793
+ def on_mixed_keys_hash(hash, do_raise); end
1794
+ end
1795
+ end
1796
+
1797
+ # JSON::Coder holds a parser and generator configuration.
1798
+ #
1799
+ # module MyApp
1800
+ # JSONC_CODER = JSON::Coder.new(
1801
+ # allow_trailing_comma: true
1802
+ # )
1803
+ # end
1804
+ #
1805
+ # MyApp::JSONC_CODER.load(document)
1806
+ #
1807
+ # pkg:gem/json#lib/json/common.rb:1045
1808
+ class JSON::Coder
1809
+ # :call-seq:
1810
+ # JSON.new(options = nil, &block)
1811
+ #
1812
+ # Argument +options+, if given, contains a \Hash of options for both parsing and generating.
1813
+ # See {Parsing Options}[rdoc-ref:JSON@Parsing+Options],
1814
+ # and {Generating Options}[rdoc-ref:JSON@Generating+Options].
1815
+ #
1816
+ # For generation, the <tt>strict: true</tt> option is always set. When a Ruby object with no native \JSON counterpart is
1817
+ # encountered, the block provided to the initialize method is invoked, and must return a Ruby object that has a native
1818
+ # \JSON counterpart:
1819
+ #
1820
+ # module MyApp
1821
+ # API_JSON_CODER = JSON::Coder.new do |object|
1822
+ # case object
1823
+ # when Time
1824
+ # object.iso8601(3)
1825
+ # else
1826
+ # object # Unknown type, will raise
1827
+ # end
1828
+ # end
1829
+ # end
1830
+ #
1831
+ # puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
1832
+ #
1833
+ # pkg:gem/json#lib/json/common.rb:1070
1834
+ def initialize(options = T.unsafe(nil), &as_json); end
1835
+
1836
+ # call-seq:
1837
+ # dump(object) -> String
1838
+ # dump(object, io) -> io
1839
+ #
1840
+ # Serialize the given object into a \JSON document.
1841
+ #
1842
+ # pkg:gem/json#lib/json/common.rb:1088
1843
+ def dump(object, io = T.unsafe(nil)); end
1844
+
1845
+ # pkg:gem/json#lib/json/common.rb:1091
1846
+ def generate(object, io = T.unsafe(nil)); end
1847
+
1848
+ # call-seq:
1849
+ # load(string) -> Object
1850
+ #
1851
+ # Parse the given \JSON document and return an equivalent Ruby object.
1852
+ #
1853
+ # pkg:gem/json#lib/json/common.rb:1097
1854
+ def load(source); end
1855
+
1856
+ # call-seq:
1857
+ # load(path) -> Object
1858
+ #
1859
+ # Parse the given \JSON document and return an equivalent Ruby object.
1860
+ #
1861
+ # pkg:gem/json#lib/json/common.rb:1106
1862
+ def load_file(path); end
1863
+
1864
+ # pkg:gem/json#lib/json/common.rb:1100
1865
+ def parse(source); end
1866
+ end
1867
+
1868
+ # pkg:gem/json#lib/json/ext.rb:39
1869
+ class JSON::Ext::Generator::State
1870
+ # call-seq: new(opts = {})
1871
+ #
1872
+ # Instantiates a new State object, configured by _opts_.
1873
+ #
1874
+ # Argument +opts+, if given, contains a \Hash of options for the generation.
1875
+ # See {Generating Options}[rdoc-ref:JSON@Generating+Options].
1876
+ #
1877
+ # pkg:gem/json#lib/json/ext.rb:39
1878
+ def initialize(opts = T.unsafe(nil)); end
1879
+
1880
+ # call-seq: [](name)
1881
+ #
1882
+ # Returns the value returned by method +name+.
1883
+ #
1884
+ # pkg:gem/json#lib/json/ext/generator/state.rb:78
1885
+ def [](name); end
1886
+
1887
+ # call-seq: []=(name, value)
1888
+ #
1889
+ # Sets the attribute name to value.
1890
+ #
1891
+ # pkg:gem/json#lib/json/ext/generator/state.rb:92
1892
+ def []=(name, value); end
1893
+
1894
+ # pkg:gem/json#lib/json/ext.rb:39
1895
+ def _generate_no_fallback(*_arg0); end
1896
+
1897
+ # pkg:gem/json#lib/json/ext.rb:39
1898
+ def allow_nan=(_arg0); end
1899
+
1900
+ # pkg:gem/json#lib/json/ext.rb:39
1901
+ def allow_nan?; end
1902
+
1903
+ # pkg:gem/json#lib/json/ext.rb:39
1904
+ def array_nl; end
1905
+
1906
+ # pkg:gem/json#lib/json/ext.rb:39
1907
+ def array_nl=(_arg0); end
1908
+
1909
+ # pkg:gem/json#lib/json/ext.rb:39
1910
+ def as_json; end
1911
+
1912
+ # pkg:gem/json#lib/json/ext.rb:39
1913
+ def as_json=(_arg0); end
1914
+
1915
+ # pkg:gem/json#lib/json/ext.rb:39
1916
+ def ascii_only=(_arg0); end
1917
+
1918
+ # pkg:gem/json#lib/json/ext.rb:39
1919
+ def ascii_only?; end
1920
+
1921
+ # pkg:gem/json#lib/json/ext.rb:39
1922
+ def buffer_initial_length; end
1923
+
1924
+ # pkg:gem/json#lib/json/ext.rb:39
1925
+ def buffer_initial_length=(_arg0); end
1926
+
1927
+ # pkg:gem/json#lib/json/ext.rb:39
1928
+ def check_circular?; end
1929
+
1930
+ # call-seq: configure(opts)
1931
+ #
1932
+ # Configure this State instance with the Hash _opts_, and return
1933
+ # itself.
1934
+ #
1935
+ # pkg:gem/json#lib/json/ext/generator/state.rb:23
1936
+ def configure(opts); end
1937
+
1938
+ # pkg:gem/json#lib/json/ext.rb:39
1939
+ def depth; end
1940
+
1941
+ # pkg:gem/json#lib/json/ext.rb:39
1942
+ def depth=(_arg0); end
1943
+
1944
+ # pkg:gem/json#lib/json/ext.rb:39
1945
+ def escape_slash; end
1946
+
1947
+ # pkg:gem/json#lib/json/ext.rb:39
1948
+ def escape_slash=(_arg0); end
1949
+
1950
+ # pkg:gem/json#lib/json/ext.rb:39
1951
+ def escape_slash?; end
1952
+
1953
+ # pkg:gem/json#lib/json/ext.rb:39
1954
+ def generate(*_arg0); end
1955
+
1956
+ # pkg:gem/json#lib/json/ext.rb:39
1957
+ def indent; end
1958
+
1959
+ # pkg:gem/json#lib/json/ext.rb:39
1960
+ def indent=(_arg0); end
1961
+
1962
+ # pkg:gem/json#lib/json/ext.rb:39
1963
+ def max_nesting; end
1964
+
1965
+ # pkg:gem/json#lib/json/ext.rb:39
1966
+ def max_nesting=(_arg0); end
1967
+
1968
+ # pkg:gem/json#lib/json/ext/generator/state.rb:36
1969
+ def merge(opts); end
1970
+
1971
+ # pkg:gem/json#lib/json/ext.rb:39
1972
+ def object_nl; end
1973
+
1974
+ # pkg:gem/json#lib/json/ext.rb:39
1975
+ def object_nl=(_arg0); end
1976
+
1977
+ # pkg:gem/json#lib/json/ext.rb:39
1978
+ def script_safe; end
1979
+
1980
+ # pkg:gem/json#lib/json/ext.rb:39
1981
+ def script_safe=(_arg0); end
1982
+
1983
+ # pkg:gem/json#lib/json/ext.rb:39
1984
+ def script_safe?; end
1985
+
1986
+ # pkg:gem/json#lib/json/ext.rb:39
1987
+ def sort_keys; end
1988
+
1989
+ # pkg:gem/json#lib/json/ext.rb:39
1990
+ def sort_keys=(_arg0); end
1991
+
1992
+ # pkg:gem/json#lib/json/ext.rb:39
1993
+ def space; end
1994
+
1995
+ # pkg:gem/json#lib/json/ext.rb:39
1996
+ def space=(_arg0); end
1997
+
1998
+ # pkg:gem/json#lib/json/ext.rb:39
1999
+ def space_before; end
2000
+
2001
+ # pkg:gem/json#lib/json/ext.rb:39
2002
+ def space_before=(_arg0); end
2003
+
2004
+ # pkg:gem/json#lib/json/ext.rb:39
2005
+ def strict; end
2006
+
2007
+ # pkg:gem/json#lib/json/ext.rb:39
2008
+ def strict=(_arg0); end
2009
+
2010
+ # pkg:gem/json#lib/json/ext.rb:39
2011
+ def strict?; end
2012
+
2013
+ # call-seq: to_h
2014
+ #
2015
+ # Returns the configuration instance variables as a hash, that can be
2016
+ # passed to the configure method.
2017
+ #
2018
+ # pkg:gem/json#lib/json/ext/generator/state.rb:42
2019
+ def to_h; end
2020
+
2021
+ # pkg:gem/json#lib/json/ext/generator/state.rb:73
2022
+ def to_hash; end
2023
+
2024
+ private
2025
+
2026
+ # pkg:gem/json#lib/json/ext.rb:39
2027
+ def _configure(_arg0); end
2028
+
2029
+ # pkg:gem/json#lib/json/ext.rb:39
2030
+ def allow_duplicate_key?; end
2031
+
2032
+ # pkg:gem/json#lib/json/ext.rb:39
2033
+ def initialize_copy(_arg0); end
2034
+
2035
+ class << self
2036
+ # pkg:gem/json#lib/json/ext.rb:39
2037
+ def _generate_no_fallback(_arg0, _arg1, _arg2); end
2038
+
2039
+ # pkg:gem/json#lib/json/ext.rb:39
2040
+ def default_sort_keys_proc=(_arg0); end
2041
+
2042
+ # pkg:gem/json#lib/json/ext.rb:39
2043
+ def from_state(_arg0); end
2044
+
2045
+ # pkg:gem/json#lib/json/ext.rb:39
2046
+ def generate(_arg0, _arg1, _arg2); end
2047
+ end
2048
+ end
2049
+
2050
+ # pkg:gem/json#lib/json/ext.rb:9
2051
+ class JSON::Ext::Parser
2052
+ # pkg:gem/json#lib/json/ext.rb:17
2053
+ def initialize(source, opts = T.unsafe(nil)); end
2054
+
2055
+ # pkg:gem/json#lib/json/ext.rb:26
2056
+ def parse; end
2057
+
2058
+ # pkg:gem/json#lib/json/ext.rb:22
2059
+ def source; end
2060
+
2061
+ class << self
2062
+ # pkg:gem/json#lib/json/ext.rb:11
2063
+ def parse(_arg0, _arg1); end
2064
+ end
2065
+ end
2066
+
2067
+ # pkg:gem/json#lib/json/ext.rb:32
2068
+ JSON::Ext::Parser::Config = JSON::Ext::ParserConfig
2069
+
2070
+ # pkg:gem/json#lib/json/ext.rb:31
2071
+ class JSON::Ext::ParserConfig
2072
+ # pkg:gem/json#lib/json/ext.rb:31
2073
+ def initialize(_arg0); end
2074
+
2075
+ # pkg:gem/json#lib/json/ext.rb:31
2076
+ def parse(_arg0); end
2077
+ end
2078
+
2079
+ # Fragment of JSON document that is to be included as is:
2080
+ # fragment = JSON::Fragment.new("[1, 2, 3]")
2081
+ # JSON.generate({ count: 3, items: fragments })
2082
+ #
2083
+ # This allows to easily assemble multiple JSON fragments that have
2084
+ # been persisted somewhere without having to parse them nor resorting
2085
+ # to string interpolation.
2086
+ #
2087
+ # Note: no validation is performed on the provided string. It is the
2088
+ # responsibility of the caller to ensure the string contains valid JSON.
2089
+ #
2090
+ # pkg:gem/json#lib/json/common.rb:298
2091
+ class JSON::Fragment < ::Struct
2092
+ # pkg:gem/json#lib/json/common.rb:299
2093
+ def initialize(json); end
2094
+
2095
+ # pkg:gem/json#lib/json/common.rb:298
2096
+ def json; end
2097
+
2098
+ # pkg:gem/json#lib/json/common.rb:298
2099
+ def json=(_); end
2100
+
2101
+ # pkg:gem/json#lib/json/common.rb:307
2102
+ def to_json(state = T.unsafe(nil), *_arg1); end
2103
+
2104
+ class << self
2105
+ # pkg:gem/json#lib/json/common.rb:298
2106
+ def [](*_arg0); end
2107
+
2108
+ # pkg:gem/json#lib/json/common.rb:298
2109
+ def inspect; end
2110
+
2111
+ # pkg:gem/json#lib/json/common.rb:298
2112
+ def keyword_init?; end
2113
+
2114
+ # pkg:gem/json#lib/json/common.rb:298
2115
+ def members; end
2116
+
2117
+ # pkg:gem/json#lib/json/common.rb:298
2118
+ def new(*_arg0); end
2119
+ end
2120
+ end
2121
+
2122
+ # This exception is raised if a generator or unparser error occurs.
2123
+ #
2124
+ # pkg:gem/json#lib/json/common.rb:268
2125
+ class JSON::GeneratorError < ::JSON::JSONError
2126
+ # pkg:gem/json#lib/json/common.rb:271
2127
+ def initialize(message, invalid_object = T.unsafe(nil)); end
2128
+
2129
+ # pkg:gem/json#lib/json/common.rb:276
2130
+ def detailed_message(*_arg0, **_arg1, &_arg2); end
2131
+
2132
+ # pkg:gem/json#lib/json/common.rb:269
2133
+ def invalid_object; end
2134
+ end
2135
+
2136
+ # pkg:gem/json#lib/json/common.rb:1111
2137
+ module JSON::GeneratorMethods
2138
+ # call-seq: to_json(*)
2139
+ #
2140
+ # Converts this object into a JSON string.
2141
+ # If this object doesn't directly maps to a JSON native type,
2142
+ # first convert it to a string (calling #to_s), then converts
2143
+ # it to a JSON string, and returns the result.
2144
+ # This is a fallback, if no special method #to_json was defined for some object.
2145
+ #
2146
+ # pkg:gem/json#lib/json/common.rb:1119
2147
+ def to_json(state = T.unsafe(nil), *_arg1); end
2148
+ end
2149
+
2150
+ # pkg:gem/json#lib/json/common.rb:367
2151
+ JSON::PARSE_L_OPTIONS = T.let(T.unsafe(nil), Hash)
2152
+
2153
+ # pkg:gem/json#lib/json/common.rb:480
2154
+ JSON::PRETTY_GENERATE_OPTIONS = T.let(T.unsafe(nil), Hash)
2155
+
2156
+ # pkg:gem/json#lib/json/common.rb:152
2157
+ JSON::Parser = JSON::Ext::Parser
2158
+
2159
+ # This exception is raised if a parser error occurs.
2160
+ #
2161
+ # pkg:gem/json#lib/json/common.rb:259
2162
+ class JSON::ParserError < ::JSON::JSONError
2163
+ # pkg:gem/json#lib/json/common.rb:260
2164
+ def column; end
2165
+
2166
+ # pkg:gem/json#lib/json/common.rb:260
2167
+ def line; end
2168
+ end
2169
+
2170
+ # pkg:gem/json#lib/json/common.rb:8
2171
+ module JSON::ParserOptions
2172
+ class << self
2173
+ # pkg:gem/json#lib/json/common.rb:10
2174
+ def prepare(opts); end
2175
+
2176
+ private
2177
+
2178
+ # pkg:gem/json#lib/json/common.rb:40
2179
+ def array_class_proc(array_class, on_load); end
2180
+
2181
+ # TODO: extract :create_additions support to another gem for version 3.0
2182
+ #
2183
+ # pkg:gem/json#lib/json/common.rb:52
2184
+ def create_additions_proc(opts); end
2185
+
2186
+ # pkg:gem/json#lib/json/common.rb:95
2187
+ def create_additions_warning; end
2188
+
2189
+ # pkg:gem/json#lib/json/common.rb:29
2190
+ def object_class_proc(object_class, on_load); end
2191
+ end
2192
+ end
2193
+
2194
+ # Not yet available on JRuby
2195
+ #
2196
+ # pkg:gem/json#lib/json/ext.rb:31
2197
+ class JSON::ResumableParser
2198
+ # pkg:gem/json#lib/json/ext.rb:31
2199
+ def initialize(*_arg0); end
2200
+
2201
+ # pkg:gem/json#lib/json/ext.rb:31
2202
+ def <<(_arg0); end
2203
+
2204
+ # pkg:gem/json#lib/json/ext.rb:31
2205
+ def clear; end
2206
+
2207
+ # Returns whether the parser is entirely done: no unconsumed bytes in
2208
+ # the buffer, no document under construction and no parsed value
2209
+ # awaiting retrieval.
2210
+ #
2211
+ # The main use case is detecting a truncated stream once the input is
2212
+ # exhausted:
2213
+ #
2214
+ # loop do
2215
+ # begin
2216
+ # parser << socket.readpartial(4096)
2217
+ # rescue EOFError
2218
+ # break
2219
+ # end
2220
+ # while parser.parse
2221
+ # process(parser.value)
2222
+ # end
2223
+ # end
2224
+ # warn "stream was truncated" unless parser.empty?
2225
+ #
2226
+ # pkg:gem/json#lib/json/ext.rb:64
2227
+ def empty?; end
2228
+
2229
+ # pkg:gem/json#lib/json/ext.rb:31
2230
+ def eos?; end
2231
+
2232
+ # pkg:gem/json#lib/json/ext.rb:31
2233
+ def parse; end
2234
+
2235
+ # pkg:gem/json#lib/json/ext.rb:31
2236
+ def parsed_bytes; end
2237
+
2238
+ # pkg:gem/json#lib/json/ext.rb:31
2239
+ def partial_value; end
2240
+
2241
+ # pkg:gem/json#lib/json/ext.rb:31
2242
+ def partial_value?; end
2243
+
2244
+ # pkg:gem/json#lib/json/ext.rb:31
2245
+ def rest; end
2246
+
2247
+ # pkg:gem/json#lib/json/ext.rb:31
2248
+ def value; end
2249
+
2250
+ # pkg:gem/json#lib/json/ext.rb:31
2251
+ def value?; end
2252
+ end
2253
+
2254
+ # pkg:gem/json#lib/json/common.rb:182
2255
+ JSON::State = JSON::Ext::Generator::State
2256
+
2257
+ # pkg:gem/json#lib/json/common.rb:1136
2258
+ module Kernel
2259
+ private
2260
+
2261
+ # If _object_ is string-like, parse the string and return the parsed result as
2262
+ # a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
2263
+ # structure object and return it.
2264
+ #
2265
+ # The _opts_ argument is passed through to generate/parse respectively. See
2266
+ # generate and parse for their documentation.
2267
+ #
2268
+ # pkg:gem/json#lib/json/common.rb:1175
2269
+ def JSON(object, opts = T.unsafe(nil)); end
2270
+
2271
+ # Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
2272
+ # one line.
2273
+ #
2274
+ # pkg:gem/json#lib/json/common.rb:1141
2275
+ def j(*objs); end
2276
+
2277
+ # Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
2278
+ # indentation and over many lines.
2279
+ #
2280
+ # pkg:gem/json#lib/json/common.rb:1156
2281
+ def jj(*objs); end
2282
+ end
2283
+
2284
+ # pkg:gem/json#lib/json/common.rb:1180
2285
+ class Object < ::BasicObject
2286
+ include ::Kernel
2287
+ include ::PP::ObjectMixin
2288
+ include ::JSON::GeneratorMethods
2289
+ end