json 2.3.1 → 2.6.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 +4 -4
- data/CHANGES.md +38 -5
- data/LICENSE +56 -0
- data/README.md +3 -3
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +61 -22
- data/ext/json/ext/generator/generator.h +5 -2
- data/ext/json/ext/parser/extconf.rb +26 -0
- data/ext/json/ext/parser/parser.c +2980 -1770
- data/ext/json/ext/parser/parser.h +6 -1
- data/ext/json/ext/parser/parser.rl +127 -38
- data/ext/json/extconf.rb +1 -0
- data/json.gemspec +8 -80
- data/lib/json/add/complex.rb +0 -1
- data/lib/json/add/rational.rb +0 -1
- data/lib/json/common.rb +240 -228
- data/lib/json/pure/generator.rb +28 -8
- data/lib/json/pure/parser.rb +21 -3
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +172 -1
- metadata +8 -110
- data/.gitignore +0 -18
- data/.travis.yml +0 -26
- data/Gemfile +0 -14
- data/README-json-jruby.md +0 -33
- data/Rakefile +0 -334
- data/diagrams/.keep +0 -0
- data/install.rb +0 -23
- data/java/src/json/ext/ByteListTranscoder.java +0 -166
- data/java/src/json/ext/Generator.java +0 -466
- data/java/src/json/ext/GeneratorMethods.java +0 -231
- data/java/src/json/ext/GeneratorService.java +0 -42
- data/java/src/json/ext/GeneratorState.java +0 -490
- data/java/src/json/ext/OptionsReader.java +0 -113
- data/java/src/json/ext/Parser.java +0 -2362
- data/java/src/json/ext/Parser.rl +0 -893
- data/java/src/json/ext/ParserService.java +0 -34
- data/java/src/json/ext/RuntimeInfo.java +0 -116
- data/java/src/json/ext/StringDecoder.java +0 -166
- data/java/src/json/ext/StringEncoder.java +0 -111
- data/java/src/json/ext/Utils.java +0 -88
- data/json-java.gemspec +0 -37
- data/json_pure.gemspec +0 -33
- data/lib/json/ext/.keep +0 -0
- data/references/rfc7159.txt +0 -899
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail18.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/obsolete_fail1.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass15.json +0 -1
- data/tests/fixtures/pass16.json +0 -1
- data/tests/fixtures/pass17.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass26.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/json_addition_test.rb +0 -203
- data/tests/json_common_interface_test.rb +0 -126
- data/tests/json_encoding_test.rb +0 -107
- data/tests/json_ext_parser_test.rb +0 -15
- data/tests/json_fixtures_test.rb +0 -37
- data/tests/json_generator_test.rb +0 -421
- data/tests/json_generic_object_test.rb +0 -82
- data/tests/json_parser_test.rb +0 -472
- data/tests/json_string_matching_test.rb +0 -38
- data/tests/test_helper.rb +0 -17
- data/tools/diff.sh +0 -18
- data/tools/fuzz.rb +0 -131
- data/tools/server.rb +0 -62
data/lib/json/pure/generator.rb
CHANGED
|
@@ -37,20 +37,26 @@ module JSON
|
|
|
37
37
|
'\\' => '\\\\',
|
|
38
38
|
} # :nodoc:
|
|
39
39
|
|
|
40
|
+
ESCAPE_SLASH_MAP = MAP.merge(
|
|
41
|
+
'/' => '\\/',
|
|
42
|
+
)
|
|
43
|
+
|
|
40
44
|
# Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
|
|
41
45
|
# UTF16 big endian characters as \u????, and return it.
|
|
42
|
-
def utf8_to_json(string) # :nodoc:
|
|
46
|
+
def utf8_to_json(string, escape_slash = false) # :nodoc:
|
|
43
47
|
string = string.dup
|
|
44
48
|
string.force_encoding(::Encoding::ASCII_8BIT)
|
|
45
|
-
|
|
49
|
+
map = escape_slash ? ESCAPE_SLASH_MAP : MAP
|
|
50
|
+
string.gsub!(/[\/"\\\x0-\x1f]/) { map[$&] || $& }
|
|
46
51
|
string.force_encoding(::Encoding::UTF_8)
|
|
47
52
|
string
|
|
48
53
|
end
|
|
49
54
|
|
|
50
|
-
def utf8_to_json_ascii(string) # :nodoc:
|
|
55
|
+
def utf8_to_json_ascii(string, escape_slash = false) # :nodoc:
|
|
51
56
|
string = string.dup
|
|
52
57
|
string.force_encoding(::Encoding::ASCII_8BIT)
|
|
53
|
-
|
|
58
|
+
map = escape_slash ? ESCAPE_SLASH_MAP : MAP
|
|
59
|
+
string.gsub!(/[\/"\\\x0-\x1f]/n) { map[$&] || $& }
|
|
54
60
|
string.gsub!(/(
|
|
55
61
|
(?:
|
|
56
62
|
[\xc2-\xdf][\x80-\xbf] |
|
|
@@ -109,6 +115,7 @@ module JSON
|
|
|
109
115
|
# * *space_before*: a string that is put before a : pair delimiter (default: ''),
|
|
110
116
|
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
|
|
111
117
|
# * *array_nl*: a string that is put at the end of a JSON array (default: ''),
|
|
118
|
+
# * *escape_slash*: true if forward slash (/) should be escaped (default: false)
|
|
112
119
|
# * *check_circular*: is deprecated now, use the :max_nesting option instead,
|
|
113
120
|
# * *max_nesting*: sets the maximum level of data structure nesting in
|
|
114
121
|
# the generated JSON, max_nesting = 0 if no maximum should be checked.
|
|
@@ -123,6 +130,7 @@ module JSON
|
|
|
123
130
|
@array_nl = ''
|
|
124
131
|
@allow_nan = false
|
|
125
132
|
@ascii_only = false
|
|
133
|
+
@escape_slash = false
|
|
126
134
|
@buffer_initial_length = 1024
|
|
127
135
|
configure opts
|
|
128
136
|
end
|
|
@@ -148,6 +156,10 @@ module JSON
|
|
|
148
156
|
# the generated JSON, max_nesting = 0 if no maximum is checked.
|
|
149
157
|
attr_accessor :max_nesting
|
|
150
158
|
|
|
159
|
+
# If this attribute is set to true, forward slashes will be escaped in
|
|
160
|
+
# all json strings.
|
|
161
|
+
attr_accessor :escape_slash
|
|
162
|
+
|
|
151
163
|
# :stopdoc:
|
|
152
164
|
attr_reader :buffer_initial_length
|
|
153
165
|
|
|
@@ -187,6 +199,11 @@ module JSON
|
|
|
187
199
|
@ascii_only
|
|
188
200
|
end
|
|
189
201
|
|
|
202
|
+
# Returns true, if forward slashes are escaped. Otherwise returns false.
|
|
203
|
+
def escape_slash?
|
|
204
|
+
@escape_slash
|
|
205
|
+
end
|
|
206
|
+
|
|
190
207
|
# Configure this State instance with the Hash _opts_, and return
|
|
191
208
|
# itself.
|
|
192
209
|
def configure(opts)
|
|
@@ -209,6 +226,7 @@ module JSON
|
|
|
209
226
|
@ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
|
|
210
227
|
@depth = opts[:depth] || 0
|
|
211
228
|
@buffer_initial_length ||= opts[:buffer_initial_length]
|
|
229
|
+
@escape_slash = !!opts[:escape_slash] if opts.key?(:escape_slash)
|
|
212
230
|
|
|
213
231
|
if !opts.key?(:max_nesting) # defaults to 100
|
|
214
232
|
@max_nesting = 100
|
|
@@ -314,8 +332,10 @@ module JSON
|
|
|
314
332
|
first = false
|
|
315
333
|
}
|
|
316
334
|
depth = state.depth -= 1
|
|
317
|
-
|
|
318
|
-
|
|
335
|
+
unless first
|
|
336
|
+
result << state.object_nl
|
|
337
|
+
result << state.indent * depth if indent
|
|
338
|
+
end
|
|
319
339
|
result << '}'
|
|
320
340
|
result
|
|
321
341
|
end
|
|
@@ -399,9 +419,9 @@ module JSON
|
|
|
399
419
|
string = encode(::Encoding::UTF_8)
|
|
400
420
|
end
|
|
401
421
|
if state.ascii_only?
|
|
402
|
-
'"' << JSON.utf8_to_json_ascii(string) << '"'
|
|
422
|
+
'"' << JSON.utf8_to_json_ascii(string, state.escape_slash) << '"'
|
|
403
423
|
else
|
|
404
|
-
'"' << JSON.utf8_to_json(string) << '"'
|
|
424
|
+
'"' << JSON.utf8_to_json(string, state.escape_slash) << '"'
|
|
405
425
|
end
|
|
406
426
|
end
|
|
407
427
|
|
data/lib/json/pure/parser.rb
CHANGED
|
@@ -45,7 +45,7 @@ module JSON
|
|
|
45
45
|
/(?=\*/) # single slash before this comment's end
|
|
46
46
|
)*
|
|
47
47
|
\*/ # the End of this comment
|
|
48
|
-
|[ \t\r\n]+ # whitespaces: space,
|
|
48
|
+
|[ \t\r\n]+ # whitespaces: space, horizontal tab, lf, cr
|
|
49
49
|
)+
|
|
50
50
|
)mx
|
|
51
51
|
|
|
@@ -61,6 +61,8 @@ module JSON
|
|
|
61
61
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
|
62
62
|
# defiance of RFC 7159 to be parsed by the Parser. This option defaults
|
|
63
63
|
# to false.
|
|
64
|
+
# * *freeze*: If set to true, all parsed objects will be frozen. Parsed
|
|
65
|
+
# string will be deduplicated if possible.
|
|
64
66
|
# * *symbolize_names*: If set to true, returns symbols for the names
|
|
65
67
|
# (keys) in a JSON object. Otherwise strings are returned, which is
|
|
66
68
|
# also the default. It's not possible to use this option in
|
|
@@ -86,6 +88,7 @@ module JSON
|
|
|
86
88
|
end
|
|
87
89
|
@allow_nan = !!opts[:allow_nan]
|
|
88
90
|
@symbolize_names = !!opts[:symbolize_names]
|
|
91
|
+
@freeze = !!opts[:freeze]
|
|
89
92
|
if opts.key?(:create_additions)
|
|
90
93
|
@create_additions = !!opts[:create_additions]
|
|
91
94
|
else
|
|
@@ -120,6 +123,7 @@ module JSON
|
|
|
120
123
|
obj = parse_value
|
|
121
124
|
UNPARSED.equal?(obj) and raise ParserError,
|
|
122
125
|
"source is not valid JSON!"
|
|
126
|
+
obj.freeze if @freeze
|
|
123
127
|
end
|
|
124
128
|
while !eos? && skip(IGNORE) do end
|
|
125
129
|
eos? or raise ParserError, "source is not valid JSON!"
|
|
@@ -161,6 +165,7 @@ module JSON
|
|
|
161
165
|
EMPTY_8BIT_STRING.force_encoding Encoding::ASCII_8BIT
|
|
162
166
|
end
|
|
163
167
|
|
|
168
|
+
STR_UMINUS = ''.respond_to?(:-@)
|
|
164
169
|
def parse_string
|
|
165
170
|
if scan(STRING)
|
|
166
171
|
return '' if self[1].empty?
|
|
@@ -180,6 +185,15 @@ module JSON
|
|
|
180
185
|
if string.respond_to?(:force_encoding)
|
|
181
186
|
string.force_encoding(::Encoding::UTF_8)
|
|
182
187
|
end
|
|
188
|
+
|
|
189
|
+
if @freeze
|
|
190
|
+
if STR_UMINUS
|
|
191
|
+
string = -string
|
|
192
|
+
else
|
|
193
|
+
string.freeze
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
183
197
|
if @create_additions and @match_string
|
|
184
198
|
for (regexp, klass) in @match_string
|
|
185
199
|
klass.json_creatable? or next
|
|
@@ -242,8 +256,10 @@ module JSON
|
|
|
242
256
|
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
|
243
257
|
result = @array_class.new
|
|
244
258
|
delim = false
|
|
245
|
-
|
|
259
|
+
loop do
|
|
246
260
|
case
|
|
261
|
+
when eos?
|
|
262
|
+
raise ParserError, "unexpected end of string while parsing array"
|
|
247
263
|
when !UNPARSED.equal?(value = parse_value)
|
|
248
264
|
delim = false
|
|
249
265
|
result << value
|
|
@@ -274,8 +290,10 @@ module JSON
|
|
|
274
290
|
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
|
275
291
|
result = @object_class.new
|
|
276
292
|
delim = false
|
|
277
|
-
|
|
293
|
+
loop do
|
|
278
294
|
case
|
|
295
|
+
when eos?
|
|
296
|
+
raise ParserError, "unexpected end of string while parsing object"
|
|
279
297
|
when !UNPARSED.equal?(string = parse_string)
|
|
280
298
|
skip(IGNORE)
|
|
281
299
|
unless scan(PAIR_DELIMITER)
|
data/lib/json/version.rb
CHANGED
data/lib/json.rb
CHANGED
|
@@ -107,6 +107,89 @@ require 'json/common'
|
|
|
107
107
|
# ruby # => nil
|
|
108
108
|
# ruby.class # => NilClass
|
|
109
109
|
#
|
|
110
|
+
# ==== Parsing Options
|
|
111
|
+
#
|
|
112
|
+
# ====== Input Options
|
|
113
|
+
#
|
|
114
|
+
# Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed;
|
|
115
|
+
# defaults to +100+; specify +false+ to disable depth checking.
|
|
116
|
+
#
|
|
117
|
+
# With the default, +false+:
|
|
118
|
+
# source = '[0, [1, [2, [3]]]]'
|
|
119
|
+
# ruby = JSON.parse(source)
|
|
120
|
+
# ruby # => [0, [1, [2, [3]]]]
|
|
121
|
+
# Too deep:
|
|
122
|
+
# # Raises JSON::NestingError (nesting of 2 is too deep):
|
|
123
|
+
# JSON.parse(source, {max_nesting: 1})
|
|
124
|
+
# Bad value:
|
|
125
|
+
# # Raises TypeError (wrong argument type Symbol (expected Fixnum)):
|
|
126
|
+
# JSON.parse(source, {max_nesting: :foo})
|
|
127
|
+
#
|
|
128
|
+
# ---
|
|
129
|
+
#
|
|
130
|
+
# Option +allow_nan+ (boolean) specifies whether to allow
|
|
131
|
+
# NaN, Infinity, and MinusInfinity in +source+;
|
|
132
|
+
# defaults to +false+.
|
|
133
|
+
#
|
|
134
|
+
# With the default, +false+:
|
|
135
|
+
# # Raises JSON::ParserError (225: unexpected token at '[NaN]'):
|
|
136
|
+
# JSON.parse('[NaN]')
|
|
137
|
+
# # Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
|
|
138
|
+
# JSON.parse('[Infinity]')
|
|
139
|
+
# # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
|
|
140
|
+
# JSON.parse('[-Infinity]')
|
|
141
|
+
# Allow:
|
|
142
|
+
# source = '[NaN, Infinity, -Infinity]'
|
|
143
|
+
# ruby = JSON.parse(source, {allow_nan: true})
|
|
144
|
+
# ruby # => [NaN, Infinity, -Infinity]
|
|
145
|
+
#
|
|
146
|
+
# ====== Output Options
|
|
147
|
+
#
|
|
148
|
+
# Option +symbolize_names+ (boolean) specifies whether returned \Hash keys
|
|
149
|
+
# should be Symbols;
|
|
150
|
+
# defaults to +false+ (use Strings).
|
|
151
|
+
#
|
|
152
|
+
# With the default, +false+:
|
|
153
|
+
# source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
|
|
154
|
+
# ruby = JSON.parse(source)
|
|
155
|
+
# ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
|
|
156
|
+
# Use Symbols:
|
|
157
|
+
# ruby = JSON.parse(source, {symbolize_names: true})
|
|
158
|
+
# ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
|
|
159
|
+
#
|
|
160
|
+
# ---
|
|
161
|
+
#
|
|
162
|
+
# Option +object_class+ (\Class) specifies the Ruby class to be used
|
|
163
|
+
# for each \JSON object;
|
|
164
|
+
# defaults to \Hash.
|
|
165
|
+
#
|
|
166
|
+
# With the default, \Hash:
|
|
167
|
+
# source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
|
|
168
|
+
# ruby = JSON.parse(source)
|
|
169
|
+
# ruby.class # => Hash
|
|
170
|
+
# Use class \OpenStruct:
|
|
171
|
+
# ruby = JSON.parse(source, {object_class: OpenStruct})
|
|
172
|
+
# ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
|
|
173
|
+
#
|
|
174
|
+
# ---
|
|
175
|
+
#
|
|
176
|
+
# Option +array_class+ (\Class) specifies the Ruby class to be used
|
|
177
|
+
# for each \JSON array;
|
|
178
|
+
# defaults to \Array.
|
|
179
|
+
#
|
|
180
|
+
# With the default, \Array:
|
|
181
|
+
# source = '["foo", 1.0, true, false, null]'
|
|
182
|
+
# ruby = JSON.parse(source)
|
|
183
|
+
# ruby.class # => Array
|
|
184
|
+
# Use class \Set:
|
|
185
|
+
# ruby = JSON.parse(source, {array_class: Set})
|
|
186
|
+
# ruby # => #<Set: {"foo", 1.0, true, false, nil}>
|
|
187
|
+
#
|
|
188
|
+
# ---
|
|
189
|
+
#
|
|
190
|
+
# Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing.
|
|
191
|
+
# See {\JSON Additions}[#module-JSON-label-JSON+Additions].
|
|
192
|
+
#
|
|
110
193
|
# === Generating \JSON
|
|
111
194
|
#
|
|
112
195
|
# To generate a Ruby \String containing \JSON data,
|
|
@@ -169,6 +252,94 @@ require 'json/common'
|
|
|
169
252
|
# JSON.generate(Complex(0, 0)) # => '"0+0i"'
|
|
170
253
|
# JSON.generate(Dir.new('.')) # => '"#<Dir>"'
|
|
171
254
|
#
|
|
255
|
+
# ==== Generating Options
|
|
256
|
+
#
|
|
257
|
+
# ====== Input Options
|
|
258
|
+
#
|
|
259
|
+
# Option +allow_nan+ (boolean) specifies whether
|
|
260
|
+
# +NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated;
|
|
261
|
+
# defaults to +false+.
|
|
262
|
+
#
|
|
263
|
+
# With the default, +false+:
|
|
264
|
+
# # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
|
|
265
|
+
# JSON.generate(JSON::NaN)
|
|
266
|
+
# # Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
|
|
267
|
+
# JSON.generate(JSON::Infinity)
|
|
268
|
+
# # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
|
|
269
|
+
# JSON.generate(JSON::MinusInfinity)
|
|
270
|
+
#
|
|
271
|
+
# Allow:
|
|
272
|
+
# ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity]
|
|
273
|
+
# JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
|
|
274
|
+
#
|
|
275
|
+
# ---
|
|
276
|
+
#
|
|
277
|
+
# Option +max_nesting+ (\Integer) specifies the maximum nesting depth
|
|
278
|
+
# in +obj+; defaults to +100+.
|
|
279
|
+
#
|
|
280
|
+
# With the default, +100+:
|
|
281
|
+
# obj = [[[[[[0]]]]]]
|
|
282
|
+
# JSON.generate(obj) # => '[[[[[[0]]]]]]'
|
|
283
|
+
#
|
|
284
|
+
# Too deep:
|
|
285
|
+
# # Raises JSON::NestingError (nesting of 2 is too deep):
|
|
286
|
+
# JSON.generate(obj, max_nesting: 2)
|
|
287
|
+
#
|
|
288
|
+
# ====== Output Options
|
|
289
|
+
#
|
|
290
|
+
# The default formatting options generate the most compact
|
|
291
|
+
# \JSON data, all on one line and with no whitespace.
|
|
292
|
+
#
|
|
293
|
+
# You can use these formatting options to generate
|
|
294
|
+
# \JSON data in a more open format, using whitespace.
|
|
295
|
+
# See also JSON.pretty_generate.
|
|
296
|
+
#
|
|
297
|
+
# - Option +array_nl+ (\String) specifies a string (usually a newline)
|
|
298
|
+
# to be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>.
|
|
299
|
+
# - Option +object_nl+ (\String) specifies a string (usually a newline)
|
|
300
|
+
# to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
|
|
301
|
+
# - Option +indent+ (\String) specifies the string (usually spaces) to be
|
|
302
|
+
# used for indentation; defaults to the empty \String, <tt>''</tt>;
|
|
303
|
+
# defaults to the empty \String, <tt>''</tt>;
|
|
304
|
+
# has no effect unless options +array_nl+ or +object_nl+ specify newlines.
|
|
305
|
+
# - Option +space+ (\String) specifies a string (usually a space) to be
|
|
306
|
+
# inserted after the colon in each \JSON object's pair;
|
|
307
|
+
# defaults to the empty \String, <tt>''</tt>.
|
|
308
|
+
# - Option +space_before+ (\String) specifies a string (usually a space) to be
|
|
309
|
+
# inserted before the colon in each \JSON object's pair;
|
|
310
|
+
# defaults to the empty \String, <tt>''</tt>.
|
|
311
|
+
#
|
|
312
|
+
# In this example, +obj+ is used first to generate the shortest
|
|
313
|
+
# \JSON data (no whitespace), then again with all formatting options
|
|
314
|
+
# specified:
|
|
315
|
+
#
|
|
316
|
+
# obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
|
|
317
|
+
# json = JSON.generate(obj)
|
|
318
|
+
# puts 'Compact:', json
|
|
319
|
+
# opts = {
|
|
320
|
+
# array_nl: "\n",
|
|
321
|
+
# object_nl: "\n",
|
|
322
|
+
# indent: ' ',
|
|
323
|
+
# space_before: ' ',
|
|
324
|
+
# space: ' '
|
|
325
|
+
# }
|
|
326
|
+
# puts 'Open:', JSON.generate(obj, opts)
|
|
327
|
+
#
|
|
328
|
+
# Output:
|
|
329
|
+
# Compact:
|
|
330
|
+
# {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
|
|
331
|
+
# Open:
|
|
332
|
+
# {
|
|
333
|
+
# "foo" : [
|
|
334
|
+
# "bar",
|
|
335
|
+
# "baz"
|
|
336
|
+
# ],
|
|
337
|
+
# "bat" : {
|
|
338
|
+
# "bam" : 0,
|
|
339
|
+
# "bad" : 1
|
|
340
|
+
# }
|
|
341
|
+
# }
|
|
342
|
+
#
|
|
172
343
|
# == \JSON Additions
|
|
173
344
|
#
|
|
174
345
|
# When you "round trip" a non-\String object from Ruby to \JSON and back,
|
|
@@ -322,7 +493,7 @@ require 'json/common'
|
|
|
322
493
|
# json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
|
|
323
494
|
# ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
|
|
324
495
|
# ruby1.class # Customer
|
|
325
|
-
|
|
496
|
+
#
|
|
326
497
|
# \Symbol:
|
|
327
498
|
# require 'json/add/symbol'
|
|
328
499
|
# ruby0 = :foo # foo
|
metadata
CHANGED
|
@@ -1,49 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: rake
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: test-unit
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '2.0'
|
|
34
|
-
- - "<"
|
|
35
|
-
- !ruby/object:Gem::Version
|
|
36
|
-
version: '4.0'
|
|
37
|
-
type: :development
|
|
38
|
-
prerelease: false
|
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
-
requirements:
|
|
41
|
-
- - ">="
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
version: '2.0'
|
|
44
|
-
- - "<"
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '4.0'
|
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
47
13
|
description: This is a JSON implementation as a Ruby extension in C.
|
|
48
14
|
email: flori@ping.de
|
|
49
15
|
executables: []
|
|
@@ -54,15 +20,10 @@ extensions:
|
|
|
54
20
|
extra_rdoc_files:
|
|
55
21
|
- README.md
|
|
56
22
|
files:
|
|
57
|
-
- ".gitignore"
|
|
58
|
-
- ".travis.yml"
|
|
59
23
|
- CHANGES.md
|
|
60
|
-
-
|
|
61
|
-
- README-json-jruby.md
|
|
24
|
+
- LICENSE
|
|
62
25
|
- README.md
|
|
63
|
-
- Rakefile
|
|
64
26
|
- VERSION
|
|
65
|
-
- diagrams/.keep
|
|
66
27
|
- ext/json/ext/fbuffer/fbuffer.h
|
|
67
28
|
- ext/json/ext/generator/depend
|
|
68
29
|
- ext/json/ext/generator/extconf.rb
|
|
@@ -74,23 +35,7 @@ files:
|
|
|
74
35
|
- ext/json/ext/parser/parser.h
|
|
75
36
|
- ext/json/ext/parser/parser.rl
|
|
76
37
|
- ext/json/extconf.rb
|
|
77
|
-
- install.rb
|
|
78
|
-
- java/src/json/ext/ByteListTranscoder.java
|
|
79
|
-
- java/src/json/ext/Generator.java
|
|
80
|
-
- java/src/json/ext/GeneratorMethods.java
|
|
81
|
-
- java/src/json/ext/GeneratorService.java
|
|
82
|
-
- java/src/json/ext/GeneratorState.java
|
|
83
|
-
- java/src/json/ext/OptionsReader.java
|
|
84
|
-
- java/src/json/ext/Parser.java
|
|
85
|
-
- java/src/json/ext/Parser.rl
|
|
86
|
-
- java/src/json/ext/ParserService.java
|
|
87
|
-
- java/src/json/ext/RuntimeInfo.java
|
|
88
|
-
- java/src/json/ext/StringDecoder.java
|
|
89
|
-
- java/src/json/ext/StringEncoder.java
|
|
90
|
-
- java/src/json/ext/Utils.java
|
|
91
|
-
- json-java.gemspec
|
|
92
38
|
- json.gemspec
|
|
93
|
-
- json_pure.gemspec
|
|
94
39
|
- lib/json.rb
|
|
95
40
|
- lib/json/add/bigdecimal.rb
|
|
96
41
|
- lib/json/add/complex.rb
|
|
@@ -108,57 +53,11 @@ files:
|
|
|
108
53
|
- lib/json/add/time.rb
|
|
109
54
|
- lib/json/common.rb
|
|
110
55
|
- lib/json/ext.rb
|
|
111
|
-
- lib/json/ext/.keep
|
|
112
56
|
- lib/json/generic_object.rb
|
|
113
57
|
- lib/json/pure.rb
|
|
114
58
|
- lib/json/pure/generator.rb
|
|
115
59
|
- lib/json/pure/parser.rb
|
|
116
60
|
- lib/json/version.rb
|
|
117
|
-
- references/rfc7159.txt
|
|
118
|
-
- tests/fixtures/fail10.json
|
|
119
|
-
- tests/fixtures/fail11.json
|
|
120
|
-
- tests/fixtures/fail12.json
|
|
121
|
-
- tests/fixtures/fail13.json
|
|
122
|
-
- tests/fixtures/fail14.json
|
|
123
|
-
- tests/fixtures/fail18.json
|
|
124
|
-
- tests/fixtures/fail19.json
|
|
125
|
-
- tests/fixtures/fail2.json
|
|
126
|
-
- tests/fixtures/fail20.json
|
|
127
|
-
- tests/fixtures/fail21.json
|
|
128
|
-
- tests/fixtures/fail22.json
|
|
129
|
-
- tests/fixtures/fail23.json
|
|
130
|
-
- tests/fixtures/fail24.json
|
|
131
|
-
- tests/fixtures/fail25.json
|
|
132
|
-
- tests/fixtures/fail27.json
|
|
133
|
-
- tests/fixtures/fail28.json
|
|
134
|
-
- tests/fixtures/fail3.json
|
|
135
|
-
- tests/fixtures/fail4.json
|
|
136
|
-
- tests/fixtures/fail5.json
|
|
137
|
-
- tests/fixtures/fail6.json
|
|
138
|
-
- tests/fixtures/fail7.json
|
|
139
|
-
- tests/fixtures/fail8.json
|
|
140
|
-
- tests/fixtures/fail9.json
|
|
141
|
-
- tests/fixtures/obsolete_fail1.json
|
|
142
|
-
- tests/fixtures/pass1.json
|
|
143
|
-
- tests/fixtures/pass15.json
|
|
144
|
-
- tests/fixtures/pass16.json
|
|
145
|
-
- tests/fixtures/pass17.json
|
|
146
|
-
- tests/fixtures/pass2.json
|
|
147
|
-
- tests/fixtures/pass26.json
|
|
148
|
-
- tests/fixtures/pass3.json
|
|
149
|
-
- tests/json_addition_test.rb
|
|
150
|
-
- tests/json_common_interface_test.rb
|
|
151
|
-
- tests/json_encoding_test.rb
|
|
152
|
-
- tests/json_ext_parser_test.rb
|
|
153
|
-
- tests/json_fixtures_test.rb
|
|
154
|
-
- tests/json_generator_test.rb
|
|
155
|
-
- tests/json_generic_object_test.rb
|
|
156
|
-
- tests/json_parser_test.rb
|
|
157
|
-
- tests/json_string_matching_test.rb
|
|
158
|
-
- tests/test_helper.rb
|
|
159
|
-
- tools/diff.sh
|
|
160
|
-
- tools/fuzz.rb
|
|
161
|
-
- tools/server.rb
|
|
162
61
|
homepage: http://flori.github.com/json
|
|
163
62
|
licenses:
|
|
164
63
|
- Ruby
|
|
@@ -172,7 +71,7 @@ metadata:
|
|
|
172
71
|
post_install_message:
|
|
173
72
|
rdoc_options:
|
|
174
73
|
- "--title"
|
|
175
|
-
- JSON
|
|
74
|
+
- JSON implementation for Ruby
|
|
176
75
|
- "--main"
|
|
177
76
|
- README.md
|
|
178
77
|
require_paths:
|
|
@@ -181,16 +80,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
181
80
|
requirements:
|
|
182
81
|
- - ">="
|
|
183
82
|
- !ruby/object:Gem::Version
|
|
184
|
-
version: '2.
|
|
83
|
+
version: '2.3'
|
|
185
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
85
|
requirements:
|
|
187
86
|
- - ">="
|
|
188
87
|
- !ruby/object:Gem::Version
|
|
189
88
|
version: '0'
|
|
190
89
|
requirements: []
|
|
191
|
-
rubygems_version: 3.
|
|
90
|
+
rubygems_version: 3.3.13
|
|
192
91
|
signing_key:
|
|
193
92
|
specification_version: 4
|
|
194
93
|
summary: JSON Implementation for Ruby
|
|
195
|
-
test_files:
|
|
196
|
-
- tests/test_helper.rb
|
|
94
|
+
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# Passes arguments to bundle install (http://gembundler.com/man/bundle-install.1.html)
|
|
2
|
-
#bundler_args: --binstubs
|
|
3
|
-
language: ruby
|
|
4
|
-
|
|
5
|
-
# Specify which ruby versions you wish to run your tests on, each version will be used
|
|
6
|
-
rvm:
|
|
7
|
-
- 2.0.0
|
|
8
|
-
- 2.1
|
|
9
|
-
- 2.2
|
|
10
|
-
- 2.3
|
|
11
|
-
- 2.4
|
|
12
|
-
- 2.5
|
|
13
|
-
- 2.6
|
|
14
|
-
- 2.7.0-preview3
|
|
15
|
-
- ruby-head
|
|
16
|
-
- jruby
|
|
17
|
-
- jruby-9.2.7.0
|
|
18
|
-
- truffleruby
|
|
19
|
-
matrix:
|
|
20
|
-
allow_failures:
|
|
21
|
-
- rvm: ruby-head
|
|
22
|
-
- rvm: jruby
|
|
23
|
-
- rvm: jruby-9.2.7.0
|
|
24
|
-
- rvm: truffleruby
|
|
25
|
-
script: "bundle exec rake"
|
|
26
|
-
sudo: false
|
data/Gemfile
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# vim: set ft=ruby:
|
|
2
|
-
|
|
3
|
-
source 'https://rubygems.org'
|
|
4
|
-
|
|
5
|
-
case ENV['JSON']
|
|
6
|
-
when 'ext', nil
|
|
7
|
-
if ENV['RUBY_ENGINE'] == 'jruby'
|
|
8
|
-
gemspec :name => 'json-java'
|
|
9
|
-
else
|
|
10
|
-
gemspec :name => 'json'
|
|
11
|
-
end
|
|
12
|
-
when 'pure'
|
|
13
|
-
gemspec :name => 'json_pure'
|
|
14
|
-
end
|
data/README-json-jruby.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
JSON-JRuby
|
|
2
|
-
==========
|
|
3
|
-
|
|
4
|
-
JSON-JRuby is a port of Florian Frank's native
|
|
5
|
-
[`json` library](http://json.rubyforge.org/) to JRuby.
|
|
6
|
-
It aims to be a perfect drop-in replacement for `json_pure`.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Development version
|
|
10
|
-
===================
|
|
11
|
-
|
|
12
|
-
The latest version is available from the
|
|
13
|
-
[Git repository](http://github.com/mernen/json-jruby/tree):
|
|
14
|
-
|
|
15
|
-
git clone git://github.com/mernen/json-jruby.git
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Compiling
|
|
19
|
-
=========
|
|
20
|
-
|
|
21
|
-
You'll need JRuby version 1.2 or greater to build JSON-JRuby.
|
|
22
|
-
Its path must be set on the `jruby.dir` property of
|
|
23
|
-
`nbproject/project.properties` (defaults to `../jruby`).
|
|
24
|
-
|
|
25
|
-
Additionally, you'll need [Ant](http://ant.apache.org/), and
|
|
26
|
-
[Ragel](http://www.cs.queensu.ca/~thurston/ragel/) 6.4 or greater.
|
|
27
|
-
|
|
28
|
-
Then, from the folder where the sources are located, type:
|
|
29
|
-
|
|
30
|
-
ant clean jar
|
|
31
|
-
|
|
32
|
-
to clean any leftovers from previous builds and generate the `.jar` files.
|
|
33
|
-
To generate a RubyGem, specify the `gem` action rather than `jar`.
|