json 3.0.0 → 3.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a457db7bd0eba155736808c796e81741e7ea72438768e183a7b7a795e8de4e
4
- data.tar.gz: 61bb013e78224c5c91f620d3097986735411befd5139f33eaecb2c3c510ababe
3
+ metadata.gz: 8462d78f66ef2dde1fbece04f33a916b97b753e1593af7ffbe27113199fe6078
4
+ data.tar.gz: 27509e760c57f937fe6e6278eebd7989d160e5779b9fce498b0afb9451de54d3
5
5
  SHA512:
6
- metadata.gz: 6e0b4b4a8160235dcef28c7924ecda754a7ae792a714e6b5fbc5baa810fd358129c4340dd1056d31df823bf139f2b42bccb9c2d400c7282079d3dcf3b2f8c2c8
7
- data.tar.gz: e67782447e1934dcada56b848982e6bb15708997b9eca220f7b631470734e0b14b2b227ac82612b03b8eb6b3d54b7686d4627a6d551d05b8252da40203f07087
6
+ metadata.gz: 6414753f43c5b3a7b97405acc7c7a732468eb0648e560eb472f04cc3880f933e5138b4dfe6af81893683603dcf511c7051dcb74ef5b8631c30a50e236ac88408
7
+ data.tar.gz: e05816e7fbdd58ab2e18cb2cee29d4354087de200f24ece9e348f05b979e62f6d69a0ab6b60ddabaf3d6cef0d0b5e00e0c0499dbdc608ddb49fc6b4d374f681c
data/CHANGES.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2026-09-09 (3.0.2)
6
+
7
+ * Fix `JSON.load_file` and `JSON.load_file!` to load on Ruby 2.7.0 through 2.7.2, which cannot parse a leading parameter before `...`.
8
+
9
+ ### 2026-09-08 (3.0.1)
10
+
11
+ * Restore the `limit` positional argument of `JSON.dump`.
12
+
5
13
  ### 2026-09-07 (3.0.0)
6
14
 
7
15
  * Add `JSON::ParserError#json_path` to locate parse errors in the document as a JSONPath-style string (e.g. `$.foo[0].bar`). For duplicate key errors it points at the duplicated key itself.
data/lib/json/common.rb CHANGED
@@ -143,11 +143,11 @@ module JSON
143
143
  # This exception is raised if a parser error occurs.
144
144
  class ParserError < JSONError
145
145
  # Line number where the parser encountered an error.
146
- # Is <tt>nil</tt> when raised by JSON::ResumableParser.
146
+ # Is +nil+ when raised by JSON::ResumableParser.
147
147
  attr_reader :line
148
148
 
149
149
  # Column number where the parser encountered an error.
150
- # Is <tt>nil</tt> when raised by JSON::ResumableParser.
150
+ # Is +nil+ when raised by JSON::ResumableParser.
151
151
  attr_reader :column
152
152
 
153
153
  # Returns a best effort JSONPath string representing where in the document
@@ -290,7 +290,7 @@ module JSON
290
290
  # ---
291
291
  #
292
292
  # Raises an exception if +source+ is not valid JSON:
293
- # # Raises JSON::ParserError unexpected character: 'invalid' at line 1 column 1 :
293
+ # # Raises JSON::ParserError (unexpected character: 'invalid' at line 1 column 1):
294
294
  # JSON.parse('invalid')
295
295
  #
296
296
  def parse(source, on_load: nil, object_class: nil, array_class: nil, **options)
@@ -324,8 +324,8 @@ module JSON
324
324
  # parse(File.read(path), **)
325
325
  #
326
326
  # See method #parse.
327
- def load_file(filespec, ...)
328
- parse(File.read(filespec, encoding: Encoding::UTF_8), ...)
327
+ def load_file(filespec, **options)
328
+ parse(File.read(filespec, encoding: Encoding::UTF_8), **options)
329
329
  end
330
330
 
331
331
  # :call-seq:
@@ -335,8 +335,8 @@ module JSON
335
335
  # JSON.parse!(File.read(path), **)
336
336
  #
337
337
  # See method #parse!
338
- def load_file!(filespec, ...)
339
- parse!(File.read(filespec, encoding: Encoding::UTF_8), ...)
338
+ def load_file!(filespec, **options)
339
+ parse!(File.read(filespec, encoding: Encoding::UTF_8), **options)
340
340
  end
341
341
 
342
342
  # :call-seq:
@@ -372,7 +372,7 @@ module JSON
372
372
  #
373
373
  # Raises an exception if +obj+ contains circular references:
374
374
  # a = []; b = []; a.push(b); b.push(a)
375
- # # Raises JSON::NestingError (nesting of 100 is too deep):
375
+ # # Raises JSON::NestingError (nesting of 100 is too deep. Did you try to serialize objects with circular references?):
376
376
  # JSON.generate(a)
377
377
  #
378
378
  def generate(obj, opts = nil)
@@ -726,16 +726,14 @@ module JSON
726
726
  end
727
727
 
728
728
  # :call-seq:
729
- # JSON.dump(obj, io = nil, options = nil)
729
+ # JSON.dump(obj, io = nil, _deprecated_limit = nil, options = nil)
730
730
  #
731
731
  # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
732
732
  #
733
- # The default options can be changed via method JSON.dump_default_options.
734
- #
735
733
  # - Argument +io+, if given, should respond to method +write+;
736
734
  # the \JSON \String is written to +io+, and +io+ is returned.
737
735
  # If +io+ is not given, the \JSON \String is returned.
738
- #
736
+ # - Argument +_deprecated_limit+ is deprecated, pass the +:max_nesting+ option instead.
739
737
  # ---
740
738
  #
741
739
  # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
@@ -751,21 +749,31 @@ module JSON
751
749
  # puts File.read(path)
752
750
  # Output:
753
751
  # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
754
- def dump(obj, anIO = nil, kwargs = nil)
752
+ def dump(obj, anIO = nil, _deprecated_limit = nil, kwargs = nil)
755
753
  if kwargs.nil?
756
- if anIO.is_a?(Hash)
757
- kwargs = anIO
758
- anIO = nil
754
+ if _deprecated_limit.nil?
755
+ if anIO.is_a?(Hash)
756
+ kwargs = anIO
757
+ anIO = nil
758
+ end
759
+ elsif _deprecated_limit.is_a?(Hash)
760
+ kwargs = _deprecated_limit
761
+ _deprecated_limit = nil
759
762
  end
760
763
  end
761
764
 
762
- if anIO&.respond_to?(:to_io)
763
- anIO = anIO.to_io
765
+ unless anIO.nil?
766
+ if anIO.respond_to?(:to_io)
767
+ anIO = anIO.to_io
768
+ elsif _deprecated_limit.nil? && !anIO.respond_to?(:write)
769
+ anIO, _deprecated_limit = nil, anIO
770
+ end
764
771
  end
765
772
 
766
773
  opts = {
767
774
  allow_nan: true,
768
775
  }
776
+ opts[:max_nesting] = _deprecated_limit if _deprecated_limit
769
777
  opts.merge!(kwargs) if kwargs
770
778
 
771
779
  State.generate(obj, opts, anIO)
@@ -804,9 +812,9 @@ module JSON
804
812
  private_constant :EXCLUDED_GENERATOR_OPTIONS
805
813
 
806
814
  # :call-seq:
807
- # JSON.new(options = nil, &block)
815
+ # JSON::Coder.new(**options, &block)
808
816
  #
809
- # Argument +options+, if given, contains a \Hash of options for both parsing and generating.
817
+ # Keyword arguments +options+, if given, are options for both parsing and generating.
810
818
  # See {Parsing Options}[rdoc-ref:JSON@Parsing+Options],
811
819
  # and {Generating Options}[rdoc-ref:JSON@Generating+Options].
812
820
  #
data/lib/json/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSON
4
- VERSION = '3.0.0'
4
+ VERSION = '3.0.2'
5
5
  end
data/lib/json.rb CHANGED
@@ -44,13 +44,13 @@ require 'json/common'
44
44
  #
45
45
  # You can parse a \String containing \JSON data using
46
46
  # either of two methods:
47
- # - <tt>JSON.parse(source, opts)</tt>
48
- # - <tt>JSON.parse!(source, opts)</tt>
47
+ # - <tt>JSON.parse(source, **opts)</tt>
48
+ # - <tt>JSON.parse!(source, **opts)</tt>
49
49
  #
50
50
  # where
51
51
  # - +source+ is a Ruby object.
52
- # - +opts+ is a \Hash object containing options
53
- # that control both input allowed and output formatting.
52
+ # - +opts+ are keyword arguments that control both input
53
+ # allowed and output formatting.
54
54
  #
55
55
  # The difference between the two methods
56
56
  # is that JSON.parse! omits some checks
@@ -102,7 +102,7 @@ require 'json/common'
102
102
  # ruby # => 1.0
103
103
  # ruby.class # => Float
104
104
  # ruby = JSON.parse('2.0e2')
105
- # ruby # => 200
105
+ # ruby # => 200.0
106
106
  # ruby.class # => Float
107
107
  # Boolean:
108
108
  # ruby = JSON.parse('true')
@@ -131,10 +131,10 @@ require 'json/common'
131
131
  # ruby # => [0, [1, [2, [3]]]]
132
132
  # Too deep:
133
133
  # # Raises JSON::NestingError (nesting of 2 is too deep):
134
- # JSON.parse(source, {max_nesting: 1})
134
+ # JSON.parse(source, max_nesting: 1)
135
135
  # Bad value:
136
- # # Raises TypeError (wrong argument type Symbol (expected Fixnum)):
137
- # JSON.parse(source, {max_nesting: :foo})
136
+ # # Raises TypeError (no implicit conversion of Symbol into Integer):
137
+ # JSON.parse(source, max_nesting: :foo)
138
138
  #
139
139
  # ---
140
140
  #
@@ -142,11 +142,11 @@ require 'json/common'
142
142
  # should be ignored or cause an error to be raised:
143
143
  #
144
144
  # When set to +false+, the default:
145
- # JSON.parse('{"a": 1, "a":2}') => duplicate key at line 1 column 1 (JSON::ParserError)
145
+ # JSON.parse('{"a": 1, "a": 2}') # duplicate key "a" at line 1 column 1 (JSON::ParserError)
146
146
  #
147
147
  # When set to +true+:
148
148
  # # The last value is used.
149
- # JSON.parse('{"a": 1, "a":2}', allow_duplicate_key: true) => {"a" => 2}
149
+ # JSON.parse('{"a": 1, "a": 2}', allow_duplicate_key: true) # => {"a" => 2}
150
150
  #
151
151
  # ---
152
152
  #
@@ -155,15 +155,15 @@ require 'json/common'
155
155
  # defaults to +false+.
156
156
  #
157
157
  # With the default, +false+:
158
- # # Raises JSON::ParserError (225: unexpected token at '[NaN]'):
158
+ # # Raises JSON::ParserError (unexpected token 'NaN]' at line 1 column 2):
159
159
  # JSON.parse('[NaN]')
160
- # # Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
160
+ # # Raises JSON::ParserError (unexpected token 'Infinity]' at line 1 column 2):
161
161
  # JSON.parse('[Infinity]')
162
- # # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
162
+ # # Raises JSON::ParserError (invalid number: '-Infinity]' at line 1 column 2):
163
163
  # JSON.parse('[-Infinity]')
164
164
  # Allow:
165
165
  # source = '[NaN, Infinity, -Infinity]'
166
- # ruby = JSON.parse(source, {allow_nan: true})
166
+ # ruby = JSON.parse(source, allow_nan: true)
167
167
  # ruby # => [NaN, Infinity, -Infinity]
168
168
  #
169
169
  # ---
@@ -185,10 +185,10 @@ require 'json/common'
185
185
  # defaults to +false+.
186
186
  #
187
187
  # When set to +false+, the default:
188
- # JSON.parse('/* comment */ {"a": 1, "a":2}') # unexpected character: '/' at line 1 column 1 (JSON::ParserError)
188
+ # JSON.parse('/* comment */ {"a": 1, "a": 2}') # unexpected token '/*' at line 1 column 1 (JSON::ParserError)
189
189
  #
190
190
  # When set to +true+, comments are ignored:
191
- # JSON.parse('/* comment */ {"a": 1, "a":2} // more comment') # => {"a" => 2}
191
+ # JSON.parse('/* comment */ {"a": 1} // more comment', allow_comments: true) # => {"a" => 1}
192
192
  #
193
193
  # ---
194
194
  #
@@ -197,7 +197,7 @@ require 'json/common'
197
197
  # defaults to +false+.
198
198
  #
199
199
  # With the default, +false+:
200
- # JSON.parse(%{"Hello\nWorld"}) # invalid ASCII control character in string (JSON::ParserError)
200
+ # JSON.parse(%{"Hello\nWorld"}) # invalid ASCII control character in string: \nWorld" at line 2 column 0 (JSON::ParserError)
201
201
  #
202
202
  # When enabled:
203
203
  # JSON.parse(%{"Hello\nWorld"}, allow_control_characters: true) # => "Hello\nWorld"
@@ -209,7 +209,7 @@ require 'json/common'
209
209
  # defaults to +false+.
210
210
  #
211
211
  # With the default, +false+:
212
- # JSON.parse('"Hell\o"') # invalid escape character in string (JSON::ParserError)
212
+ # JSON.parse('"Hell\o"') # invalid escape character in string: '\o"' at line 1 column 6 (JSON::ParserError)
213
213
  #
214
214
  # When enabled:
215
215
  # JSON.parse('"Hell\o"', allow_invalid_escape: true) # => "Hello"
@@ -228,8 +228,8 @@ require 'json/common'
228
228
  # ruby = JSON.parse(source)
229
229
  # ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
230
230
  # Use Symbols:
231
- # ruby = JSON.parse(source, {symbolize_names: true})
232
- # ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
231
+ # ruby = JSON.parse(source, symbolize_names: true)
232
+ # ruby # => {a: "foo", b: 1.0, c: true, d: false, e: nil}
233
233
  #
234
234
  # ---
235
235
  #
@@ -242,7 +242,7 @@ require 'json/common'
242
242
  # ruby = JSON.parse(source)
243
243
  # ruby.class # => Hash
244
244
  # Use class \OpenStruct:
245
- # ruby = JSON.parse(source, {object_class: OpenStruct})
245
+ # ruby = JSON.parse(source, object_class: OpenStruct)
246
246
  # ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
247
247
  #
248
248
  # ---
@@ -256,8 +256,8 @@ require 'json/common'
256
256
  # ruby = JSON.parse(source)
257
257
  # ruby.class # => Array
258
258
  # Use class \Set:
259
- # ruby = JSON.parse(source, {array_class: Set})
260
- # ruby # => #<Set: {"foo", 1.0, true, false, nil}>
259
+ # ruby = JSON.parse(source, array_class: Set)
260
+ # ruby # => Set["foo", 1.0, true, false, nil]
261
261
  #
262
262
  # === Generating \JSON
263
263
  #
@@ -319,22 +319,22 @@ require 'json/common'
319
319
  # a \String containing a \JSON string representation of the source:
320
320
  # JSON.generate(:foo) # => '"foo"'
321
321
  # JSON.generate(Complex(0, 0)) # => '"0+0i"'
322
- # JSON.generate(Dir.new('.')) # => '"#<Dir>"'
322
+ # JSON.generate(Dir.new('.')) # => '"#<Dir:0x...>"'
323
323
  #
324
324
  # ==== Generating Options
325
325
  #
326
326
  # ====== Input Options
327
327
  #
328
328
  # Option +allow_nan+ (boolean) specifies whether
329
- # +NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated;
329
+ # +NaN+, +Infinity+, and +-Infinity+ may be generated;
330
330
  # defaults to +false+.
331
331
  #
332
332
  # With the default, +false+:
333
- # # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
333
+ # # Raises JSON::GeneratorError (NaN not allowed in JSON):
334
334
  # JSON.generate(JSON::NaN)
335
- # # Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
335
+ # # Raises JSON::GeneratorError (Infinity not allowed in JSON):
336
336
  # JSON.generate(JSON::Infinity)
337
- # # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
337
+ # # Raises JSON::GeneratorError (-Infinity not allowed in JSON):
338
338
  # JSON.generate(JSON::MinusInfinity)
339
339
  #
340
340
  # Allow:
@@ -345,14 +345,14 @@ require 'json/common'
345
345
  #
346
346
  # Option +allow_duplicate_key+ (boolean) specifies whether
347
347
  # hashes with duplicate keys should be allowed or produce an error.
348
- # defaults to emit a deprecation warning.
348
+ # Defaults to +false+, which raises an error.
349
349
  #
350
- # With the default, <tt>false</tt>:
351
- # JSON.generate({ foo: 1, "foo" => 2 })
350
+ # With the default, +false+:
351
+ # JSON.generate({foo: 1, "foo" => 2})
352
352
  # # detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
353
353
  #
354
- # With <tt>true</tt>
355
- # JSON.generate({ foo: 1, "foo" => 2 }, allow_duplicate_key: true)
354
+ # With +true+:
355
+ # JSON.generate({foo: 1, "foo" => 2}, allow_duplicate_key: true)
356
356
  # # => '{"foo":1,"foo":2}'
357
357
  #
358
358
  # ---
@@ -365,13 +365,13 @@ require 'json/common'
365
365
  # JSON.generate(obj) # => '[[[[[[0]]]]]]'
366
366
  #
367
367
  # Too deep:
368
- # # Raises JSON::NestingError (nesting of 2 is too deep):
368
+ # # Raises JSON::NestingError (nesting of 2 is too deep. Did you try to serialize objects with circular references?):
369
369
  # JSON.generate(obj, max_nesting: 2)
370
370
  #
371
371
  # With +false+:
372
372
  # obj = []
373
373
  # obj[0] = obj
374
- # # Raises SystemStackError: stack level too deep
374
+ # # Raises SystemStackError (stack level too deep):
375
375
  # JSON.generate(obj, max_nesting: false)
376
376
  #
377
377
  # Setting +max_nesting+ to +false+ or a very large number can lead to a stack overflow
@@ -410,7 +410,7 @@ require 'json/common'
410
410
  # inserted before the colon in each \JSON object's pair;
411
411
  # defaults to the empty \String, <tt>''</tt>.
412
412
  # - Option +sort_keys+ (boolean or \Proc) controls whether and how the keys of a
413
- # hash are sorted when generating the output; defaults to <tt>false</tt>.
413
+ # hash are sorted when generating the output; defaults to +false+.
414
414
  # When +true+, keys are sorted lexicographically. When a \Proc, it receives
415
415
  # the entire \Hash and must return a \Hash with its pairs in the desired
416
416
  # order, allowing for arbitrary sort orders.
@@ -439,7 +439,7 @@ require 'json/common'
439
439
  # "foo" : [
440
440
  # "bar",
441
441
  # "baz"
442
- # ],
442
+ # ],
443
443
  # "bat" : {
444
444
  # "bam" : 0,
445
445
  # "bad" : 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank