json 2.10.2 → 2.12.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.
- checksums.yaml +4 -4
- data/CHANGES.md +47 -0
- data/ext/json/ext/fbuffer/fbuffer.h +45 -14
- data/ext/json/ext/generator/extconf.rb +29 -0
- data/ext/json/ext/generator/generator.c +467 -100
- data/ext/json/ext/generator/simd.h +112 -0
- data/ext/json/ext/parser/extconf.rb +0 -1
- data/ext/json/ext/parser/parser.c +160 -242
- data/ext/json/ext/vendor/fpconv.c +479 -0
- data/ext/json/ext/vendor/jeaiii-ltoa.h +267 -0
- data/lib/json/common.rb +277 -160
- data/lib/json/truffle_ruby/generator.rb +1 -1
- data/lib/json/version.rb +1 -1
- metadata +5 -2
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,32 +220,24 @@ 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
|
-
class ParserError < JSONError
|
233
|
+
class ParserError < JSONError
|
234
|
+
attr_reader :line, :column
|
235
|
+
end
|
136
236
|
|
137
237
|
# This exception is raised if the nesting of parsed data structures is too
|
138
238
|
# deep.
|
139
239
|
class NestingError < ParserError; end
|
140
240
|
|
141
|
-
# :stopdoc:
|
142
|
-
class CircularDatastructure < NestingError; end
|
143
|
-
# :startdoc:
|
144
|
-
|
145
241
|
# This exception is raised if a generator or unparser error occurs.
|
146
242
|
class GeneratorError < JSONError
|
147
243
|
attr_reader :invalid_object
|
@@ -163,13 +259,6 @@ module JSON
|
|
163
259
|
end
|
164
260
|
end
|
165
261
|
|
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
262
|
# Fragment of JSON document that is to be included as is:
|
174
263
|
# fragment = JSON::Fragment.new("[1, 2, 3]")
|
175
264
|
# JSON.generate({ count: 3, items: fragments })
|
@@ -245,9 +334,16 @@ module JSON
|
|
245
334
|
# JSON.parse('')
|
246
335
|
#
|
247
336
|
def parse(source, opts = nil)
|
337
|
+
opts = ParserOptions.prepare(opts) unless opts.nil?
|
248
338
|
Parser.parse(source, opts)
|
249
339
|
end
|
250
340
|
|
341
|
+
PARSE_L_OPTIONS = {
|
342
|
+
max_nesting: false,
|
343
|
+
allow_nan: true,
|
344
|
+
}.freeze
|
345
|
+
private_constant :PARSE_L_OPTIONS
|
346
|
+
|
251
347
|
# :call-seq:
|
252
348
|
# JSON.parse!(source, opts) -> object
|
253
349
|
#
|
@@ -260,12 +356,11 @@ module JSON
|
|
260
356
|
# which disables checking for nesting depth.
|
261
357
|
# - Option +allow_nan+, if not provided, defaults to +true+.
|
262
358
|
def parse!(source, opts = nil)
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
Parser.new(source, options).parse
|
359
|
+
if opts.nil?
|
360
|
+
parse(source, PARSE_L_OPTIONS)
|
361
|
+
else
|
362
|
+
parse(source, PARSE_L_OPTIONS.merge(opts))
|
363
|
+
end
|
269
364
|
end
|
270
365
|
|
271
366
|
# :call-seq:
|
@@ -334,13 +429,6 @@ module JSON
|
|
334
429
|
end
|
335
430
|
end
|
336
431
|
|
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
432
|
# :call-seq:
|
345
433
|
# JSON.fast_generate(obj, opts) -> new_string
|
346
434
|
#
|
@@ -355,19 +443,21 @@ module JSON
|
|
355
443
|
# # Raises SystemStackError (stack level too deep):
|
356
444
|
# JSON.fast_generate(a)
|
357
445
|
def fast_generate(obj, opts = nil)
|
358
|
-
if
|
359
|
-
|
446
|
+
if RUBY_VERSION >= "3.0"
|
447
|
+
warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
|
360
448
|
else
|
361
|
-
|
449
|
+
warn "JSON.fast_generate is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
|
362
450
|
end
|
363
|
-
|
451
|
+
generate(obj, opts)
|
364
452
|
end
|
365
453
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
454
|
+
PRETTY_GENERATE_OPTIONS = {
|
455
|
+
indent: ' ',
|
456
|
+
space: ' ',
|
457
|
+
object_nl: "\n",
|
458
|
+
array_nl: "\n",
|
459
|
+
}.freeze
|
460
|
+
private_constant :PRETTY_GENERATE_OPTIONS
|
371
461
|
|
372
462
|
# :call-seq:
|
373
463
|
# JSON.pretty_generate(obj, opts = nil) -> new_string
|
@@ -400,52 +490,46 @@ module JSON
|
|
400
490
|
# }
|
401
491
|
#
|
402
492
|
def pretty_generate(obj, opts = nil)
|
403
|
-
if State === opts
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
end
|
493
|
+
return state.generate(obj) if State === opts
|
494
|
+
|
495
|
+
options = PRETTY_GENERATE_OPTIONS
|
496
|
+
|
408
497
|
if opts
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
498
|
+
unless opts.is_a?(Hash)
|
499
|
+
if opts.respond_to? :to_hash
|
500
|
+
opts = opts.to_hash
|
501
|
+
elsif opts.respond_to? :to_h
|
502
|
+
opts = opts.to_h
|
503
|
+
else
|
504
|
+
raise TypeError, "can't convert #{opts.class} into Hash"
|
505
|
+
end
|
415
506
|
end
|
416
|
-
|
507
|
+
options = options.merge(opts)
|
417
508
|
end
|
418
|
-
|
509
|
+
|
510
|
+
State.generate(obj, options, nil)
|
419
511
|
end
|
420
512
|
|
421
|
-
#
|
422
|
-
#
|
423
|
-
|
424
|
-
|
425
|
-
|
513
|
+
# Sets or returns default options for the JSON.unsafe_load method.
|
514
|
+
# Initially:
|
515
|
+
# opts = JSON.load_default_options
|
516
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
517
|
+
deprecated_singleton_attr_accessor :unsafe_load_default_options
|
426
518
|
|
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 = {
|
519
|
+
@unsafe_load_default_options = {
|
435
520
|
:max_nesting => false,
|
436
521
|
:allow_nan => true,
|
437
522
|
:allow_blank => true,
|
438
523
|
:create_additions => true,
|
439
524
|
}
|
440
525
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
self.load_default_options = {
|
526
|
+
# Sets or returns default options for the JSON.load method.
|
527
|
+
# Initially:
|
528
|
+
# opts = JSON.load_default_options
|
529
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
530
|
+
deprecated_singleton_attr_accessor :load_default_options
|
531
|
+
|
532
|
+
@load_default_options = {
|
449
533
|
:allow_nan => true,
|
450
534
|
:allow_blank => true,
|
451
535
|
:create_additions => nil,
|
@@ -581,9 +665,9 @@ module JSON
|
|
581
665
|
#
|
582
666
|
def unsafe_load(source, proc = nil, options = nil)
|
583
667
|
opts = if options.nil?
|
584
|
-
|
668
|
+
_unsafe_load_default_options
|
585
669
|
else
|
586
|
-
|
670
|
+
_unsafe_load_default_options.merge(options)
|
587
671
|
end
|
588
672
|
|
589
673
|
unless source.is_a?(String)
|
@@ -741,9 +825,9 @@ module JSON
|
|
741
825
|
#
|
742
826
|
def load(source, proc = nil, options = nil)
|
743
827
|
opts = if options.nil?
|
744
|
-
|
828
|
+
_load_default_options
|
745
829
|
else
|
746
|
-
|
830
|
+
_load_default_options.merge(options)
|
747
831
|
end
|
748
832
|
|
749
833
|
unless source.is_a?(String)
|
@@ -759,36 +843,21 @@ module JSON
|
|
759
843
|
if opts[:allow_blank] && (source.nil? || source.empty?)
|
760
844
|
source = 'null'
|
761
845
|
end
|
762
|
-
result = parse(source, opts)
|
763
|
-
recurse_proc(result, &proc) if proc
|
764
|
-
result
|
765
|
-
end
|
766
846
|
|
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
|
847
|
+
if proc
|
848
|
+
opts = opts.dup
|
849
|
+
opts[:on_load] = proc.to_proc
|
778
850
|
end
|
779
|
-
end
|
780
851
|
|
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
|
852
|
+
parse(source, opts)
|
790
853
|
end
|
791
|
-
|
854
|
+
|
855
|
+
# Sets or returns the default options for the JSON.dump method.
|
856
|
+
# Initially:
|
857
|
+
# opts = JSON.dump_default_options
|
858
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true}
|
859
|
+
deprecated_singleton_attr_accessor :dump_default_options
|
860
|
+
@dump_default_options = {
|
792
861
|
:max_nesting => false,
|
793
862
|
:allow_nan => true,
|
794
863
|
}
|
@@ -841,7 +910,7 @@ module JSON
|
|
841
910
|
end
|
842
911
|
end
|
843
912
|
|
844
|
-
opts = JSON.
|
913
|
+
opts = JSON._dump_default_options
|
845
914
|
opts = opts.merge(:max_nesting => limit) if limit
|
846
915
|
opts = opts.merge(kwargs) if kwargs
|
847
916
|
|
@@ -852,10 +921,67 @@ module JSON
|
|
852
921
|
end
|
853
922
|
end
|
854
923
|
|
855
|
-
#
|
856
|
-
|
857
|
-
|
924
|
+
# :stopdoc:
|
925
|
+
# All these were meant to be deprecated circa 2009, but were just set as undocumented
|
926
|
+
# so usage still exist in the wild.
|
927
|
+
def unparse(...)
|
928
|
+
if RUBY_VERSION >= "3.0"
|
929
|
+
warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
|
930
|
+
else
|
931
|
+
warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
|
932
|
+
end
|
933
|
+
generate(...)
|
858
934
|
end
|
935
|
+
module_function :unparse
|
936
|
+
|
937
|
+
def fast_unparse(...)
|
938
|
+
if RUBY_VERSION >= "3.0"
|
939
|
+
warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
|
940
|
+
else
|
941
|
+
warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
|
942
|
+
end
|
943
|
+
generate(...)
|
944
|
+
end
|
945
|
+
module_function :fast_unparse
|
946
|
+
|
947
|
+
def pretty_unparse(...)
|
948
|
+
if RUBY_VERSION >= "3.0"
|
949
|
+
warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1, category: :deprecated
|
950
|
+
else
|
951
|
+
warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1
|
952
|
+
end
|
953
|
+
pretty_generate(...)
|
954
|
+
end
|
955
|
+
module_function :fast_unparse
|
956
|
+
|
957
|
+
def restore(...)
|
958
|
+
if RUBY_VERSION >= "3.0"
|
959
|
+
warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1, category: :deprecated
|
960
|
+
else
|
961
|
+
warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1
|
962
|
+
end
|
963
|
+
load(...)
|
964
|
+
end
|
965
|
+
module_function :restore
|
966
|
+
|
967
|
+
class << self
|
968
|
+
private
|
969
|
+
|
970
|
+
def const_missing(const_name)
|
971
|
+
case const_name
|
972
|
+
when :PRETTY_STATE_PROTOTYPE
|
973
|
+
if RUBY_VERSION >= "3.0"
|
974
|
+
warn "JSON::PRETTY_STATE_PROTOTYPE is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1, category: :deprecated
|
975
|
+
else
|
976
|
+
warn "JSON::PRETTY_STATE_PROTOTYPE is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1
|
977
|
+
end
|
978
|
+
state.new(PRETTY_GENERATE_OPTIONS)
|
979
|
+
else
|
980
|
+
super
|
981
|
+
end
|
982
|
+
end
|
983
|
+
end
|
984
|
+
# :startdoc:
|
859
985
|
|
860
986
|
# JSON::Coder holds a parser and generator configuration.
|
861
987
|
#
|
@@ -899,10 +1025,9 @@ module JSON
|
|
899
1025
|
options[:strict] = true
|
900
1026
|
end
|
901
1027
|
options[:as_json] = as_json if as_json
|
902
|
-
options[:create_additions] = false unless options.key?(:create_additions)
|
903
1028
|
|
904
1029
|
@state = State.new(options).freeze
|
905
|
-
@parser_config = Ext::Parser::Config.new(options)
|
1030
|
+
@parser_config = Ext::Parser::Config.new(ParserOptions.prepare(options))
|
906
1031
|
end
|
907
1032
|
|
908
1033
|
# call-seq:
|
@@ -940,6 +1065,12 @@ module ::Kernel
|
|
940
1065
|
# Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
|
941
1066
|
# one line.
|
942
1067
|
def j(*objs)
|
1068
|
+
if RUBY_VERSION >= "3.0"
|
1069
|
+
warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
|
1070
|
+
else
|
1071
|
+
warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1
|
1072
|
+
end
|
1073
|
+
|
943
1074
|
objs.each do |obj|
|
944
1075
|
puts JSON::generate(obj, :allow_nan => true, :max_nesting => false)
|
945
1076
|
end
|
@@ -949,6 +1080,12 @@ module ::Kernel
|
|
949
1080
|
# Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
|
950
1081
|
# indentation and over many lines.
|
951
1082
|
def jj(*objs)
|
1083
|
+
if RUBY_VERSION >= "3.0"
|
1084
|
+
warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
|
1085
|
+
else
|
1086
|
+
warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1
|
1087
|
+
end
|
1088
|
+
|
952
1089
|
objs.each do |obj|
|
953
1090
|
puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)
|
954
1091
|
end
|
@@ -961,27 +1098,7 @@ module ::Kernel
|
|
961
1098
|
#
|
962
1099
|
# The _opts_ argument is passed through to generate/parse respectively. See
|
963
1100
|
# 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)
|
1101
|
+
def JSON(object, opts = nil)
|
1102
|
+
JSON[object, opts]
|
986
1103
|
end
|
987
1104
|
end
|
data/lib/json/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-05-12 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: This is a JSON implementation as a Ruby extension in C.
|
13
13
|
email: flori@ping.de
|
@@ -26,8 +26,11 @@ files:
|
|
26
26
|
- ext/json/ext/fbuffer/fbuffer.h
|
27
27
|
- ext/json/ext/generator/extconf.rb
|
28
28
|
- ext/json/ext/generator/generator.c
|
29
|
+
- ext/json/ext/generator/simd.h
|
29
30
|
- ext/json/ext/parser/extconf.rb
|
30
31
|
- ext/json/ext/parser/parser.c
|
32
|
+
- ext/json/ext/vendor/fpconv.c
|
33
|
+
- ext/json/ext/vendor/jeaiii-ltoa.h
|
31
34
|
- json.gemspec
|
32
35
|
- lib/json.rb
|
33
36
|
- lib/json/add/bigdecimal.rb
|