json 2.10.2-java → 2.11.1-java
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 +4 -4
- data/CHANGES.md +29 -0
- data/lib/json/common.rb +256 -159
- data/lib/json/ext/generator.jar +0 -0
- data/lib/json/ext/parser.jar +0 -0
- data/lib/json/truffle_ruby/generator.rb +1 -1
- data/lib/json/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09e8ff0151f4a70f6400293c68aee23c7b5b3e2ca8fa042f755ca2b3346fc59
|
4
|
+
data.tar.gz: 59c24f5f8de7c032c1d101ff1e80d09b84bb419e155f93a74e158a0e0fc8cac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fe3a381366f4f9494431a4730782fc19124c62aed5b4090ee43fa28c90f26674abbdd86d5a22f61e211bc0a2eabaf607725c060332c42f7c09e32eb66a38770
|
7
|
+
data.tar.gz: '0807e1eeaf0069d25b9382e2553b52f018183ddc6acee40c90da1e181bfc59eab6fceae20abe56d3d395ae53edc9be83bb0daa0bf52f5b456bee504acc9f451b'
|
data/CHANGES.md
CHANGED
@@ -1,10 +1,39 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
### 2025-04-24 (2.11.1)
|
4
|
+
|
5
|
+
* Add back `JSON.restore`, `JSON.unparse`, `JSON.fast_unparse` and `JSON.pretty_unparse`.
|
6
|
+
These were deprecated 16 years ago, but never emited warnings, only undocumented, so are
|
7
|
+
still used by a few gems.
|
8
|
+
|
9
|
+
### 2025-04-24 (2.11.0)
|
10
|
+
|
11
|
+
* Optimize Integer generation to be ~1.8x faster.
|
12
|
+
* Optimize Float generation to be ~10x faster.
|
13
|
+
* Fix `JSON.load` proc argument to substitute the parsed object with the return value.
|
14
|
+
This better match `Marshal.load` behavior.
|
15
|
+
* Deprecate `JSON.fast_generate` (it's not any faster, so pointless).
|
16
|
+
* Deprecate `JSON.load_default_options`.
|
17
|
+
* Deprecate `JSON.unsafe_load_default_options`.
|
18
|
+
* Deprecate `JSON.dump_default_options`.
|
19
|
+
* Deprecate `Kernel#j`
|
20
|
+
* Deprecate `Kernel#jj`
|
21
|
+
* Remove outdated `JSON.iconv`.
|
22
|
+
* Remove `Class#json_creatable?` monkey patch.
|
23
|
+
* Remove deprecated `JSON.restore` method.
|
24
|
+
* Remove deprecated `JSON.unparse` method.
|
25
|
+
* Remove deprecated `JSON.fast_unparse` method.
|
26
|
+
* Remove deprecated `JSON.pretty_unparse` method.
|
27
|
+
* Remove deprecated `JSON::UnparserError` constant.
|
28
|
+
* Remove outdated `JSON::MissingUnicodeSupport` constant.
|
29
|
+
|
3
30
|
### 2025-03-12 (2.10.2)
|
4
31
|
|
5
32
|
* Fix a potential crash in the C extension parser.
|
6
33
|
* Raise a ParserError on all incomplete unicode escape sequence. This was the behavior until `2.10.0` unadvertently changed it.
|
7
34
|
* Ensure document snippets that are included in parser errors don't include truncated multibyte characters.
|
35
|
+
* Ensure parser error snippets are valid UTF-8.
|
36
|
+
* Fix `JSON::GeneratorError#detailed_message` on Ruby < 3.2
|
8
37
|
|
9
38
|
### 2025-02-10 (2.10.1)
|
10
39
|
|
data/lib/json/common.rb
CHANGED
@@ -5,8 +5,111 @@ require 'json/version'
|
|
5
5
|
module JSON
|
6
6
|
autoload :GenericObject, 'json/generic_object'
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
module ParserOptions # :nodoc:
|
9
|
+
class << self
|
10
|
+
def prepare(opts)
|
11
|
+
if opts[:object_class] || opts[:array_class]
|
12
|
+
opts = opts.dup
|
13
|
+
on_load = opts[:on_load]
|
14
|
+
|
15
|
+
on_load = object_class_proc(opts[:object_class], on_load) if opts[:object_class]
|
16
|
+
on_load = array_class_proc(opts[:array_class], on_load) if opts[:array_class]
|
17
|
+
opts[:on_load] = on_load
|
18
|
+
end
|
19
|
+
|
20
|
+
if opts.fetch(:create_additions, false) != false
|
21
|
+
opts = create_additions_proc(opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
opts
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def object_class_proc(object_class, on_load)
|
30
|
+
->(obj) do
|
31
|
+
if Hash === obj
|
32
|
+
object = object_class.new
|
33
|
+
obj.each { |k, v| object[k] = v }
|
34
|
+
obj = object
|
35
|
+
end
|
36
|
+
on_load.nil? ? obj : on_load.call(obj)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def array_class_proc(array_class, on_load)
|
41
|
+
->(obj) do
|
42
|
+
if Array === obj
|
43
|
+
array = array_class.new
|
44
|
+
obj.each { |v| array << v }
|
45
|
+
obj = array
|
46
|
+
end
|
47
|
+
on_load.nil? ? obj : on_load.call(obj)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# TODO: exctract :create_additions support to another gem for version 3.0
|
52
|
+
def create_additions_proc(opts)
|
53
|
+
if opts[:symbolize_names]
|
54
|
+
raise ArgumentError, "options :symbolize_names and :create_additions cannot be used in conjunction"
|
55
|
+
end
|
56
|
+
|
57
|
+
opts = opts.dup
|
58
|
+
create_additions = opts.fetch(:create_additions, false)
|
59
|
+
on_load = opts[:on_load]
|
60
|
+
object_class = opts[:object_class] || Hash
|
61
|
+
|
62
|
+
opts[:on_load] = ->(object) do
|
63
|
+
case object
|
64
|
+
when String
|
65
|
+
opts[:match_string]&.each do |pattern, klass|
|
66
|
+
if match = pattern.match(object)
|
67
|
+
create_additions_warning if create_additions.nil?
|
68
|
+
object = klass.json_create(object)
|
69
|
+
break
|
70
|
+
end
|
71
|
+
end
|
72
|
+
when object_class
|
73
|
+
if opts[:create_additions] != false
|
74
|
+
if class_name = object[JSON.create_id]
|
75
|
+
klass = JSON.deep_const_get(class_name)
|
76
|
+
if (klass.respond_to?(:json_creatable?) && klass.json_creatable?) || klass.respond_to?(:json_create)
|
77
|
+
create_additions_warning if create_additions.nil?
|
78
|
+
object = klass.json_create(object)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
on_load.nil? ? object : on_load.call(object)
|
85
|
+
end
|
86
|
+
|
87
|
+
opts
|
88
|
+
end
|
89
|
+
|
90
|
+
GEM_ROOT = File.expand_path("../../../", __FILE__) + "/"
|
91
|
+
def create_additions_warning
|
92
|
+
message = "JSON.load implicit support for `create_additions: true` is deprecated " \
|
93
|
+
"and will be removed in 3.0, use JSON.unsafe_load or explicitly " \
|
94
|
+
"pass `create_additions: true`"
|
95
|
+
|
96
|
+
uplevel = 4
|
97
|
+
caller_locations(uplevel, 10).each do |frame|
|
98
|
+
if frame.path.nil? || frame.path.start_with?(GEM_ROOT) || frame.path.end_with?("/truffle/cext_ruby.rb", ".c")
|
99
|
+
uplevel += 1
|
100
|
+
else
|
101
|
+
break
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
if RUBY_VERSION >= "3.0"
|
106
|
+
warn(message, uplevel: uplevel - 1, category: :deprecated)
|
107
|
+
else
|
108
|
+
warn(message, uplevel: uplevel - 1)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
10
113
|
|
11
114
|
class << self
|
12
115
|
# :call-seq:
|
@@ -20,7 +123,7 @@ module JSON
|
|
20
123
|
# Otherwise, calls JSON.generate with +object+ and +opts+ (see method #generate):
|
21
124
|
# ruby = [0, 1, nil]
|
22
125
|
# JSON[ruby] # => '[0,1,null]'
|
23
|
-
def [](object, opts =
|
126
|
+
def [](object, opts = nil)
|
24
127
|
if object.is_a?(String)
|
25
128
|
return JSON.parse(object, opts)
|
26
129
|
elsif object.respond_to?(:to_str)
|
@@ -70,37 +173,38 @@ module JSON
|
|
70
173
|
end
|
71
174
|
self.state = generator::State
|
72
175
|
const_set :State, self.state
|
73
|
-
const_set :SAFE_STATE_PROTOTYPE, State.new # for JRuby
|
74
|
-
const_set :FAST_STATE_PROTOTYPE, create_fast_state
|
75
|
-
const_set :PRETTY_STATE_PROTOTYPE, create_pretty_state
|
76
176
|
ensure
|
77
177
|
$VERBOSE = old
|
78
178
|
end
|
79
179
|
|
80
|
-
def create_fast_state
|
81
|
-
State.new(
|
82
|
-
:indent => '',
|
83
|
-
:space => '',
|
84
|
-
:object_nl => "",
|
85
|
-
:array_nl => "",
|
86
|
-
:max_nesting => false
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
def create_pretty_state
|
91
|
-
State.new(
|
92
|
-
:indent => ' ',
|
93
|
-
:space => ' ',
|
94
|
-
:object_nl => "\n",
|
95
|
-
:array_nl => "\n"
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
180
|
# Returns the JSON generator module that is used by JSON.
|
100
181
|
attr_reader :generator
|
101
182
|
|
102
183
|
# Sets or Returns the JSON generator state class that is used by JSON.
|
103
184
|
attr_accessor :state
|
185
|
+
|
186
|
+
private
|
187
|
+
|
188
|
+
def deprecated_singleton_attr_accessor(*attrs)
|
189
|
+
args = RUBY_VERSION >= "3.0" ? ", category: :deprecated" : ""
|
190
|
+
attrs.each do |attr|
|
191
|
+
singleton_class.class_eval <<~RUBY
|
192
|
+
def #{attr}
|
193
|
+
warn "JSON.#{attr} is deprecated and will be removed in json 3.0.0", uplevel: 1 #{args}
|
194
|
+
@#{attr}
|
195
|
+
end
|
196
|
+
|
197
|
+
def #{attr}=(val)
|
198
|
+
warn "JSON.#{attr}= is deprecated and will be removed in json 3.0.0", uplevel: 1 #{args}
|
199
|
+
@#{attr} = val
|
200
|
+
end
|
201
|
+
|
202
|
+
def _#{attr}
|
203
|
+
@#{attr}
|
204
|
+
end
|
205
|
+
RUBY
|
206
|
+
end
|
207
|
+
end
|
104
208
|
end
|
105
209
|
|
106
210
|
# Sets create identifier, which is used to decide if the _json_create_
|
@@ -116,20 +220,14 @@ module JSON
|
|
116
220
|
Thread.current[:"JSON.create_id"] || 'json_class'
|
117
221
|
end
|
118
222
|
|
119
|
-
NaN =
|
223
|
+
NaN = Float::NAN
|
120
224
|
|
121
|
-
Infinity =
|
225
|
+
Infinity = Float::INFINITY
|
122
226
|
|
123
227
|
MinusInfinity = -Infinity
|
124
228
|
|
125
229
|
# The base exception for JSON errors.
|
126
|
-
class JSONError < StandardError
|
127
|
-
def self.wrap(exception)
|
128
|
-
obj = new("Wrapped(#{exception.class}): #{exception.message.inspect}")
|
129
|
-
obj.set_backtrace exception.backtrace
|
130
|
-
obj
|
131
|
-
end
|
132
|
-
end
|
230
|
+
class JSONError < StandardError; end
|
133
231
|
|
134
232
|
# This exception is raised if a parser error occurs.
|
135
233
|
class ParserError < JSONError; end
|
@@ -138,10 +236,6 @@ module JSON
|
|
138
236
|
# deep.
|
139
237
|
class NestingError < ParserError; end
|
140
238
|
|
141
|
-
# :stopdoc:
|
142
|
-
class CircularDatastructure < NestingError; end
|
143
|
-
# :startdoc:
|
144
|
-
|
145
239
|
# This exception is raised if a generator or unparser error occurs.
|
146
240
|
class GeneratorError < JSONError
|
147
241
|
attr_reader :invalid_object
|
@@ -163,13 +257,6 @@ module JSON
|
|
163
257
|
end
|
164
258
|
end
|
165
259
|
|
166
|
-
# For backwards compatibility
|
167
|
-
UnparserError = GeneratorError # :nodoc:
|
168
|
-
|
169
|
-
# This exception is raised if the required unicode support is missing on the
|
170
|
-
# system. Usually this means that the iconv library is not installed.
|
171
|
-
class MissingUnicodeSupport < JSONError; end
|
172
|
-
|
173
260
|
# Fragment of JSON document that is to be included as is:
|
174
261
|
# fragment = JSON::Fragment.new("[1, 2, 3]")
|
175
262
|
# JSON.generate({ count: 3, items: fragments })
|
@@ -245,9 +332,16 @@ module JSON
|
|
245
332
|
# JSON.parse('')
|
246
333
|
#
|
247
334
|
def parse(source, opts = nil)
|
335
|
+
opts = ParserOptions.prepare(opts) unless opts.nil?
|
248
336
|
Parser.parse(source, opts)
|
249
337
|
end
|
250
338
|
|
339
|
+
PARSE_L_OPTIONS = {
|
340
|
+
max_nesting: false,
|
341
|
+
allow_nan: true,
|
342
|
+
}.freeze
|
343
|
+
private_constant :PARSE_L_OPTIONS
|
344
|
+
|
251
345
|
# :call-seq:
|
252
346
|
# JSON.parse!(source, opts) -> object
|
253
347
|
#
|
@@ -260,12 +354,11 @@ module JSON
|
|
260
354
|
# which disables checking for nesting depth.
|
261
355
|
# - Option +allow_nan+, if not provided, defaults to +true+.
|
262
356
|
def parse!(source, opts = nil)
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
Parser.new(source, options).parse
|
357
|
+
if opts.nil?
|
358
|
+
parse(source, PARSE_L_OPTIONS)
|
359
|
+
else
|
360
|
+
parse(source, PARSE_L_OPTIONS.merge(opts))
|
361
|
+
end
|
269
362
|
end
|
270
363
|
|
271
364
|
# :call-seq:
|
@@ -334,13 +427,6 @@ module JSON
|
|
334
427
|
end
|
335
428
|
end
|
336
429
|
|
337
|
-
# :stopdoc:
|
338
|
-
# I want to deprecate these later, so I'll first be silent about them, and
|
339
|
-
# later delete them.
|
340
|
-
alias unparse generate
|
341
|
-
module_function :unparse
|
342
|
-
# :startdoc:
|
343
|
-
|
344
430
|
# :call-seq:
|
345
431
|
# JSON.fast_generate(obj, opts) -> new_string
|
346
432
|
#
|
@@ -355,19 +441,21 @@ module JSON
|
|
355
441
|
# # Raises SystemStackError (stack level too deep):
|
356
442
|
# JSON.fast_generate(a)
|
357
443
|
def fast_generate(obj, opts = nil)
|
358
|
-
if
|
359
|
-
|
444
|
+
if RUBY_VERSION >= "3.0"
|
445
|
+
warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
|
360
446
|
else
|
361
|
-
|
447
|
+
warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
|
362
448
|
end
|
363
|
-
|
449
|
+
generate(obj, opts)
|
364
450
|
end
|
365
451
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
452
|
+
PRETTY_GENERATE_OPTIONS = {
|
453
|
+
indent: ' ',
|
454
|
+
space: ' ',
|
455
|
+
object_nl: "\n",
|
456
|
+
array_nl: "\n",
|
457
|
+
}.freeze
|
458
|
+
private_constant :PRETTY_GENERATE_OPTIONS
|
371
459
|
|
372
460
|
# :call-seq:
|
373
461
|
# JSON.pretty_generate(obj, opts = nil) -> new_string
|
@@ -400,52 +488,46 @@ module JSON
|
|
400
488
|
# }
|
401
489
|
#
|
402
490
|
def pretty_generate(obj, opts = nil)
|
403
|
-
if State === opts
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
end
|
491
|
+
return state.generate(obj) if State === opts
|
492
|
+
|
493
|
+
options = PRETTY_GENERATE_OPTIONS
|
494
|
+
|
408
495
|
if opts
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
496
|
+
unless opts.is_a?(Hash)
|
497
|
+
if opts.respond_to? :to_hash
|
498
|
+
opts = opts.to_hash
|
499
|
+
elsif opts.respond_to? :to_h
|
500
|
+
opts = opts.to_h
|
501
|
+
else
|
502
|
+
raise TypeError, "can't convert #{opts.class} into Hash"
|
503
|
+
end
|
415
504
|
end
|
416
|
-
|
505
|
+
options = options.merge(opts)
|
417
506
|
end
|
418
|
-
|
507
|
+
|
508
|
+
State.generate(obj, options, nil)
|
419
509
|
end
|
420
510
|
|
421
|
-
#
|
422
|
-
#
|
423
|
-
|
424
|
-
|
425
|
-
|
511
|
+
# Sets or returns default options for the JSON.unsafe_load method.
|
512
|
+
# Initially:
|
513
|
+
# opts = JSON.load_default_options
|
514
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
515
|
+
deprecated_singleton_attr_accessor :unsafe_load_default_options
|
426
516
|
|
427
|
-
|
428
|
-
# Sets or returns default options for the JSON.unsafe_load method.
|
429
|
-
# Initially:
|
430
|
-
# opts = JSON.load_default_options
|
431
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
432
|
-
attr_accessor :unsafe_load_default_options
|
433
|
-
end
|
434
|
-
self.unsafe_load_default_options = {
|
517
|
+
@unsafe_load_default_options = {
|
435
518
|
:max_nesting => false,
|
436
519
|
:allow_nan => true,
|
437
520
|
:allow_blank => true,
|
438
521
|
:create_additions => true,
|
439
522
|
}
|
440
523
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
self.load_default_options = {
|
524
|
+
# Sets or returns default options for the JSON.load method.
|
525
|
+
# Initially:
|
526
|
+
# opts = JSON.load_default_options
|
527
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
528
|
+
deprecated_singleton_attr_accessor :load_default_options
|
529
|
+
|
530
|
+
@load_default_options = {
|
449
531
|
:allow_nan => true,
|
450
532
|
:allow_blank => true,
|
451
533
|
:create_additions => nil,
|
@@ -581,9 +663,9 @@ module JSON
|
|
581
663
|
#
|
582
664
|
def unsafe_load(source, proc = nil, options = nil)
|
583
665
|
opts = if options.nil?
|
584
|
-
|
666
|
+
_unsafe_load_default_options
|
585
667
|
else
|
586
|
-
|
668
|
+
_unsafe_load_default_options.merge(options)
|
587
669
|
end
|
588
670
|
|
589
671
|
unless source.is_a?(String)
|
@@ -741,9 +823,9 @@ module JSON
|
|
741
823
|
#
|
742
824
|
def load(source, proc = nil, options = nil)
|
743
825
|
opts = if options.nil?
|
744
|
-
|
826
|
+
_load_default_options
|
745
827
|
else
|
746
|
-
|
828
|
+
_load_default_options.merge(options)
|
747
829
|
end
|
748
830
|
|
749
831
|
unless source.is_a?(String)
|
@@ -759,36 +841,21 @@ module JSON
|
|
759
841
|
if opts[:allow_blank] && (source.nil? || source.empty?)
|
760
842
|
source = 'null'
|
761
843
|
end
|
762
|
-
result = parse(source, opts)
|
763
|
-
recurse_proc(result, &proc) if proc
|
764
|
-
result
|
765
|
-
end
|
766
844
|
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
when Array
|
771
|
-
result.each { |x| recurse_proc x, &proc }
|
772
|
-
proc.call result
|
773
|
-
when Hash
|
774
|
-
result.each { |x, y| recurse_proc x, &proc; recurse_proc y, &proc }
|
775
|
-
proc.call result
|
776
|
-
else
|
777
|
-
proc.call result
|
845
|
+
if proc
|
846
|
+
opts = opts.dup
|
847
|
+
opts[:on_load] = proc.to_proc
|
778
848
|
end
|
779
|
-
end
|
780
849
|
|
781
|
-
|
782
|
-
module_function :restore
|
783
|
-
|
784
|
-
class << self
|
785
|
-
# Sets or returns the default options for the JSON.dump method.
|
786
|
-
# Initially:
|
787
|
-
# opts = JSON.dump_default_options
|
788
|
-
# opts # => {:max_nesting=>false, :allow_nan=>true}
|
789
|
-
attr_accessor :dump_default_options
|
850
|
+
parse(source, opts)
|
790
851
|
end
|
791
|
-
|
852
|
+
|
853
|
+
# Sets or returns the default options for the JSON.dump method.
|
854
|
+
# Initially:
|
855
|
+
# opts = JSON.dump_default_options
|
856
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true}
|
857
|
+
deprecated_singleton_attr_accessor :dump_default_options
|
858
|
+
@dump_default_options = {
|
792
859
|
:max_nesting => false,
|
793
860
|
:allow_nan => true,
|
794
861
|
}
|
@@ -841,7 +908,7 @@ module JSON
|
|
841
908
|
end
|
842
909
|
end
|
843
910
|
|
844
|
-
opts = JSON.
|
911
|
+
opts = JSON._dump_default_options
|
845
912
|
opts = opts.merge(:max_nesting => limit) if limit
|
846
913
|
opts = opts.merge(kwargs) if kwargs
|
847
914
|
|
@@ -852,10 +919,49 @@ module JSON
|
|
852
919
|
end
|
853
920
|
end
|
854
921
|
|
855
|
-
#
|
856
|
-
|
857
|
-
|
922
|
+
# :stopdoc:
|
923
|
+
# All these were meant to be deprecated circa 2009, but were just set as undocumented
|
924
|
+
# so usage still exist in the wild.
|
925
|
+
def unparse(...)
|
926
|
+
if RUBY_VERSION >= "3.0"
|
927
|
+
warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
|
928
|
+
else
|
929
|
+
warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
|
930
|
+
end
|
931
|
+
generate(...)
|
858
932
|
end
|
933
|
+
module_function :unparse
|
934
|
+
|
935
|
+
def fast_unparse(...)
|
936
|
+
if RUBY_VERSION >= "3.0"
|
937
|
+
warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
|
938
|
+
else
|
939
|
+
warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
|
940
|
+
end
|
941
|
+
generate(...)
|
942
|
+
end
|
943
|
+
module_function :fast_unparse
|
944
|
+
|
945
|
+
def pretty_unparse(...)
|
946
|
+
if RUBY_VERSION >= "3.0"
|
947
|
+
warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1, category: :deprecated
|
948
|
+
else
|
949
|
+
warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1
|
950
|
+
end
|
951
|
+
pretty_generate(...)
|
952
|
+
end
|
953
|
+
module_function :fast_unparse
|
954
|
+
|
955
|
+
def restore(...)
|
956
|
+
if RUBY_VERSION >= "3.0"
|
957
|
+
warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1, category: :deprecated
|
958
|
+
else
|
959
|
+
warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1
|
960
|
+
end
|
961
|
+
load(...)
|
962
|
+
end
|
963
|
+
module_function :restore
|
964
|
+
# :startdoc:
|
859
965
|
|
860
966
|
# JSON::Coder holds a parser and generator configuration.
|
861
967
|
#
|
@@ -899,10 +1005,9 @@ module JSON
|
|
899
1005
|
options[:strict] = true
|
900
1006
|
end
|
901
1007
|
options[:as_json] = as_json if as_json
|
902
|
-
options[:create_additions] = false unless options.key?(:create_additions)
|
903
1008
|
|
904
1009
|
@state = State.new(options).freeze
|
905
|
-
@parser_config = Ext::Parser::Config.new(options)
|
1010
|
+
@parser_config = Ext::Parser::Config.new(ParserOptions.prepare(options))
|
906
1011
|
end
|
907
1012
|
|
908
1013
|
# call-seq:
|
@@ -940,6 +1045,12 @@ module ::Kernel
|
|
940
1045
|
# Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
|
941
1046
|
# one line.
|
942
1047
|
def j(*objs)
|
1048
|
+
if RUBY_VERSION >= "3.0"
|
1049
|
+
warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
|
1050
|
+
else
|
1051
|
+
warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1
|
1052
|
+
end
|
1053
|
+
|
943
1054
|
objs.each do |obj|
|
944
1055
|
puts JSON::generate(obj, :allow_nan => true, :max_nesting => false)
|
945
1056
|
end
|
@@ -949,6 +1060,12 @@ module ::Kernel
|
|
949
1060
|
# Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
|
950
1061
|
# indentation and over many lines.
|
951
1062
|
def jj(*objs)
|
1063
|
+
if RUBY_VERSION >= "3.0"
|
1064
|
+
warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
|
1065
|
+
else
|
1066
|
+
warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1
|
1067
|
+
end
|
1068
|
+
|
952
1069
|
objs.each do |obj|
|
953
1070
|
puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)
|
954
1071
|
end
|
@@ -961,27 +1078,7 @@ module ::Kernel
|
|
961
1078
|
#
|
962
1079
|
# The _opts_ argument is passed through to generate/parse respectively. See
|
963
1080
|
# generate and parse for their documentation.
|
964
|
-
def JSON(object,
|
965
|
-
|
966
|
-
return JSON.parse(object, args.first)
|
967
|
-
elsif object.respond_to?(:to_str)
|
968
|
-
str = object.to_str
|
969
|
-
if str.is_a?(String)
|
970
|
-
return JSON.parse(object.to_str, args.first)
|
971
|
-
end
|
972
|
-
end
|
973
|
-
|
974
|
-
JSON.generate(object, args.first)
|
975
|
-
end
|
976
|
-
end
|
977
|
-
|
978
|
-
# Extends any Class to include _json_creatable?_ method.
|
979
|
-
class ::Class
|
980
|
-
# Returns true if this class can be used to create an instance
|
981
|
-
# from a serialised JSON string. The class has to implement a class
|
982
|
-
# method _json_create_ that expects a hash as first parameter. The hash
|
983
|
-
# should include the required data.
|
984
|
-
def json_creatable?
|
985
|
-
respond_to?(:json_create)
|
1081
|
+
def JSON(object, opts = nil)
|
1082
|
+
JSON[object, opts]
|
986
1083
|
end
|
987
1084
|
end
|
data/lib/json/ext/generator.jar
CHANGED
Binary file
|
data/lib/json/ext/parser.jar
CHANGED
Binary file
|
data/lib/json/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.11.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Daniel Luz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A JSON implementation as a JRuby extension.
|
14
14
|
email: dev+ruby@mernen.com
|