json 1.8.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{CHANGES → CHANGES.md} +251 -87
- data/{COPYING-json-jruby → LICENSE} +5 -6
- data/README.md +425 -0
- data/VERSION +1 -1
- data/ext/json/ext/fbuffer/fbuffer.h +10 -4
- data/ext/json/ext/generator/extconf.rb +0 -10
- data/ext/json/ext/generator/generator.c +308 -135
- data/ext/json/ext/generator/generator.h +35 -9
- data/ext/json/ext/parser/extconf.rb +25 -6
- data/ext/json/ext/parser/parser.c +3035 -1901
- data/ext/json/ext/parser/parser.h +29 -10
- data/ext/json/ext/parser/parser.rl +261 -211
- data/ext/json/extconf.rb +3 -0
- data/json.gemspec +57 -27
- data/lib/json/add/bigdecimal.rb +3 -2
- data/lib/json/add/complex.rb +9 -3
- data/lib/json/add/core.rb +1 -0
- data/lib/json/add/date.rb +1 -1
- data/lib/json/add/date_time.rb +1 -1
- data/lib/json/add/exception.rb +1 -1
- data/lib/json/add/ostruct.rb +3 -3
- data/lib/json/add/range.rb +1 -1
- data/lib/json/add/rational.rb +8 -3
- data/lib/json/add/regexp.rb +3 -3
- data/lib/json/add/set.rb +29 -0
- data/lib/json/add/struct.rb +1 -1
- data/lib/json/add/symbol.rb +1 -1
- data/lib/json/add/time.rb +2 -2
- data/lib/json/common.rb +383 -167
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +5 -4
- data/lib/json/pure/generator.rb +83 -126
- data/lib/json/pure/parser.rb +63 -85
- data/lib/json/pure.rb +2 -8
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +550 -29
- metadata +29 -136
- data/.gitignore +0 -12
- data/.travis.yml +0 -20
- data/COPYING +0 -58
- data/GPL +0 -340
- data/Gemfile +0 -11
- data/README-json-jruby.markdown +0 -33
- data/README.rdoc +0 -358
- data/Rakefile +0 -412
- data/TODO +0 -1
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
- data/diagrams/.keep +0 -0
- data/install.rb +0 -23
- data/java/src/json/ext/ByteListTranscoder.java +0 -167
- data/java/src/json/ext/Generator.java +0 -444
- data/java/src/json/ext/GeneratorMethods.java +0 -232
- data/java/src/json/ext/GeneratorService.java +0 -43
- data/java/src/json/ext/GeneratorState.java +0 -543
- data/java/src/json/ext/OptionsReader.java +0 -114
- data/java/src/json/ext/Parser.java +0 -2644
- data/java/src/json/ext/Parser.rl +0 -968
- data/java/src/json/ext/ParserService.java +0 -35
- data/java/src/json/ext/RuntimeInfo.java +0 -121
- data/java/src/json/ext/StringDecoder.java +0 -167
- data/java/src/json/ext/StringEncoder.java +0 -106
- data/java/src/json/ext/Utils.java +0 -89
- data/json-java.gemspec +0 -23
- data/json_pure.gemspec +0 -39
- data/lib/json/ext/.keep +0 -0
- data/tests/fixtures/fail1.json +0 -1
- 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/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/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -545
- data/tests/test_json_addition.rb +0 -196
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_fixtures.rb +0 -35
- data/tests/test_json_generate.rb +0 -322
- data/tests/test_json_generic_object.rb +0 -75
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
- data/tools/fuzz.rb +0 -139
- data/tools/server.rb +0 -62
data/README.md
ADDED
@@ -0,0 +1,425 @@
|
|
1
|
+
# JSON implementation for Ruby
|
2
|
+
|
3
|
+
[![CI](https://github.com/flori/json/actions/workflows/ci.yml/badge.svg)](https://github.com/flori/json/actions/workflows/ci.yml)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
This is a implementation of the JSON specification according to RFC 7159
|
8
|
+
http://www.ietf.org/rfc/rfc7159.txt . Starting from version 1.0.0 on there
|
9
|
+
will be two variants available:
|
10
|
+
|
11
|
+
* A pure ruby variant, that relies on the iconv and the stringscan
|
12
|
+
extensions, which are both part of the ruby standard library.
|
13
|
+
* The quite a bit faster native extension variant, which is in parts
|
14
|
+
implemented in C or Java and comes with its own unicode conversion
|
15
|
+
functions and a parser generated by the ragel state machine compiler
|
16
|
+
http://www.complang.org/ragel/ .
|
17
|
+
|
18
|
+
Both variants of the JSON generator generate UTF-8 character sequences by
|
19
|
+
default. If an :ascii\_only option with a true value is given, they escape all
|
20
|
+
non-ASCII and control characters with \uXXXX escape sequences, and support
|
21
|
+
UTF-16 surrogate pairs in order to be able to generate the whole range of
|
22
|
+
unicode code points.
|
23
|
+
|
24
|
+
All strings, that are to be encoded as JSON strings, should be UTF-8 byte
|
25
|
+
sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
|
26
|
+
encoded, please use the to\_json\_raw\_object method of String (which produces
|
27
|
+
an object, that contains a byte array) and decode the result on the receiving
|
28
|
+
endpoint.
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
It's recommended to use the extension variant of JSON, because it's faster than
|
33
|
+
the pure ruby variant. If you cannot build it on your system, you can settle
|
34
|
+
for the latter.
|
35
|
+
|
36
|
+
Just type into the command line as root:
|
37
|
+
|
38
|
+
```
|
39
|
+
# rake install
|
40
|
+
```
|
41
|
+
|
42
|
+
The above command will build the extensions and install them on your system.
|
43
|
+
|
44
|
+
```
|
45
|
+
# rake install_pure
|
46
|
+
```
|
47
|
+
|
48
|
+
or
|
49
|
+
|
50
|
+
```
|
51
|
+
# ruby install.rb
|
52
|
+
```
|
53
|
+
|
54
|
+
will just install the pure ruby implementation of JSON.
|
55
|
+
|
56
|
+
If you use Rubygems you can type
|
57
|
+
|
58
|
+
```
|
59
|
+
# gem install json
|
60
|
+
```
|
61
|
+
|
62
|
+
instead, to install the newest JSON version.
|
63
|
+
|
64
|
+
There is also a pure ruby json only variant of the gem, that can be installed
|
65
|
+
with:
|
66
|
+
|
67
|
+
```
|
68
|
+
# gem install json_pure
|
69
|
+
```
|
70
|
+
|
71
|
+
## Compiling the extensions yourself
|
72
|
+
|
73
|
+
If you want to create the `parser.c` file from its `parser.rl` file or draw nice
|
74
|
+
graphviz images of the state machines, you need ragel from:
|
75
|
+
http://www.complang.org/ragel/
|
76
|
+
|
77
|
+
## Usage
|
78
|
+
|
79
|
+
To use JSON you can
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
require 'json'
|
83
|
+
```
|
84
|
+
|
85
|
+
to load the installed variant (either the extension `'json'` or the pure
|
86
|
+
variant `'json_pure'`). If you have installed the extension variant, you can
|
87
|
+
pick either the extension variant or the pure variant by typing
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'json/ext'
|
91
|
+
```
|
92
|
+
|
93
|
+
or
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
require 'json/pure'
|
97
|
+
```
|
98
|
+
|
99
|
+
Now you can parse a JSON document into a ruby data structure by calling
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
JSON.parse(document)
|
103
|
+
```
|
104
|
+
|
105
|
+
If you want to generate a JSON document from a ruby data structure call
|
106
|
+
```ruby
|
107
|
+
JSON.generate(data)
|
108
|
+
```
|
109
|
+
|
110
|
+
You can also use the `pretty_generate` method (which formats the output more
|
111
|
+
verbosely and nicely) or `fast_generate` (which doesn't do any of the security
|
112
|
+
checks generate performs, e. g. nesting deepness checks).
|
113
|
+
|
114
|
+
There are also the JSON and JSON[] methods which use parse on a String or
|
115
|
+
generate a JSON document from an array or hash:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
document = JSON 'test' => 23 # => "{\"test\":23}"
|
119
|
+
document = JSON['test' => 23] # => "{\"test\":23}"
|
120
|
+
```
|
121
|
+
|
122
|
+
and
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
data = JSON '{"test":23}' # => {"test"=>23}
|
126
|
+
data = JSON['{"test":23}'] # => {"test"=>23}
|
127
|
+
```
|
128
|
+
|
129
|
+
You can choose to load a set of common additions to ruby core's objects if
|
130
|
+
you
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
require 'json/add/core'
|
134
|
+
```
|
135
|
+
|
136
|
+
After requiring this you can, e. g., serialise/deserialise Ruby ranges:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
JSON JSON(1..10) # => 1..10
|
140
|
+
```
|
141
|
+
|
142
|
+
To find out how to add JSON support to other or your own classes, read the
|
143
|
+
section "More Examples" below.
|
144
|
+
|
145
|
+
To get the best compatibility to rails' JSON implementation, you can
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
require 'json/add/rails'
|
149
|
+
```
|
150
|
+
|
151
|
+
Both of the additions attempt to require `'json'` (like above) first, if it has
|
152
|
+
not been required yet.
|
153
|
+
|
154
|
+
## Serializing exceptions
|
155
|
+
|
156
|
+
The JSON module doesn't extend `Exception` by default. If you convert an `Exception`
|
157
|
+
object to JSON, it will by default only include the exception message.
|
158
|
+
|
159
|
+
To include the full details, you must either load the `json/add/core` mentioned
|
160
|
+
above, or specifically load the exception addition:
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
require 'json/add/exception'
|
164
|
+
```
|
165
|
+
|
166
|
+
## More Examples
|
167
|
+
|
168
|
+
To create a JSON document from a ruby data structure, you can call
|
169
|
+
`JSON.generate` like that:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
173
|
+
# => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
|
174
|
+
```
|
175
|
+
|
176
|
+
To get back a ruby data structure from a JSON document, you have to call
|
177
|
+
JSON.parse on it:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
JSON.parse json
|
181
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
182
|
+
```
|
183
|
+
|
184
|
+
Note, that the range from the original data structure is a simple
|
185
|
+
string now. The reason for this is, that JSON doesn't support ranges
|
186
|
+
or arbitrary classes. In this case the json library falls back to call
|
187
|
+
`Object#to_json`, which is the same as `#to_s.to_json`.
|
188
|
+
|
189
|
+
It's possible to add JSON support serialization to arbitrary classes by
|
190
|
+
simply implementing a more specialized version of the `#to_json method`, that
|
191
|
+
should return a JSON object (a hash converted to JSON with `#to_json`) like
|
192
|
+
this (don't forget the `*a` for all the arguments):
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
class Range
|
196
|
+
def to_json(*a)
|
197
|
+
{
|
198
|
+
'json_class' => self.class.name, # = 'Range'
|
199
|
+
'data' => [ first, last, exclude_end? ]
|
200
|
+
}.to_json(*a)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
The hash key `json_class` is the class, that will be asked to deserialise the
|
206
|
+
JSON representation later. In this case it's `Range`, but any namespace of
|
207
|
+
the form `A::B` or `::A::B` will do. All other keys are arbitrary and can be
|
208
|
+
used to store the necessary data to configure the object to be deserialised.
|
209
|
+
|
210
|
+
If the key `json_class` is found in a JSON object, the JSON parser checks
|
211
|
+
if the given class responds to the `json_create` class method. If so, it is
|
212
|
+
called with the JSON object converted to a Ruby hash. So a range can
|
213
|
+
be deserialised by implementing `Range.json_create` like this:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
class Range
|
217
|
+
def self.json_create(o)
|
218
|
+
new(*o['data'])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
```
|
222
|
+
|
223
|
+
Now it possible to serialise/deserialise ranges as well:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
227
|
+
# => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
228
|
+
JSON.parse json
|
229
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
230
|
+
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
231
|
+
# => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
232
|
+
JSON.parse json, :create_additions => true
|
233
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
234
|
+
```
|
235
|
+
|
236
|
+
`JSON.generate` always creates the shortest possible string representation of a
|
237
|
+
ruby data structure in one line. This is good for data storage or network
|
238
|
+
protocols, but not so good for humans to read. Fortunately there's also
|
239
|
+
`JSON.pretty_generate` (or `JSON.pretty_generate`) that creates a more readable
|
240
|
+
output:
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
|
244
|
+
[
|
245
|
+
1,
|
246
|
+
2,
|
247
|
+
{
|
248
|
+
"a": 3.141
|
249
|
+
},
|
250
|
+
false,
|
251
|
+
true,
|
252
|
+
null,
|
253
|
+
{
|
254
|
+
"json_class": "Range",
|
255
|
+
"data": [
|
256
|
+
4,
|
257
|
+
10,
|
258
|
+
false
|
259
|
+
]
|
260
|
+
}
|
261
|
+
]
|
262
|
+
```
|
263
|
+
|
264
|
+
There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
|
265
|
+
`pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
|
266
|
+
the `pp` library's `pp` methods.
|
267
|
+
|
268
|
+
The script `tools/server.rb` contains a small example if you want to test, how
|
269
|
+
receiving a JSON object from a webrick server in your browser with the
|
270
|
+
JavaScript prototype library http://www.prototypejs.org works.
|
271
|
+
|
272
|
+
## Speed Comparisons
|
273
|
+
|
274
|
+
I have created some benchmark results (see the benchmarks/data-p4-3Ghz
|
275
|
+
subdir of the package) for the JSON-parser to estimate the speed up in the C
|
276
|
+
extension:
|
277
|
+
|
278
|
+
```
|
279
|
+
Comparing times (call_time_mean):
|
280
|
+
1 ParserBenchmarkExt#parser 900 repeats:
|
281
|
+
553.922304770 ( real) -> 21.500x
|
282
|
+
0.001805307
|
283
|
+
2 ParserBenchmarkYAML#parser 1000 repeats:
|
284
|
+
224.513358139 ( real) -> 8.714x
|
285
|
+
0.004454078
|
286
|
+
3 ParserBenchmarkPure#parser 1000 repeats:
|
287
|
+
26.755020642 ( real) -> 1.038x
|
288
|
+
0.037376163
|
289
|
+
4 ParserBenchmarkRails#parser 1000 repeats:
|
290
|
+
25.763381731 ( real) -> 1.000x
|
291
|
+
0.038814780
|
292
|
+
calls/sec ( time) -> speed covers
|
293
|
+
secs/call
|
294
|
+
```
|
295
|
+
|
296
|
+
In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
|
297
|
+
compatible JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
|
298
|
+
`ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
|
299
|
+
input first to YAML and then uses the YAML-parser, the conversion seems to
|
300
|
+
slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
|
301
|
+
|
302
|
+
If you look at the benchmark data you can see that this is mostly caused by
|
303
|
+
the frequent high outliers - the median of the Rails-parser runs is still
|
304
|
+
overall smaller than the median of the `JSON::Pure::Parser` runs:
|
305
|
+
|
306
|
+
```
|
307
|
+
Comparing times (call_time_median):
|
308
|
+
1 ParserBenchmarkExt#parser 900 repeats:
|
309
|
+
800.592479481 ( real) -> 26.936x
|
310
|
+
0.001249075
|
311
|
+
2 ParserBenchmarkYAML#parser 1000 repeats:
|
312
|
+
271.002390644 ( real) -> 9.118x
|
313
|
+
0.003690004
|
314
|
+
3 ParserBenchmarkRails#parser 1000 repeats:
|
315
|
+
30.227910865 ( real) -> 1.017x
|
316
|
+
0.033082008
|
317
|
+
4 ParserBenchmarkPure#parser 1000 repeats:
|
318
|
+
29.722384421 ( real) -> 1.000x
|
319
|
+
0.033644676
|
320
|
+
calls/sec ( time) -> speed covers
|
321
|
+
secs/call
|
322
|
+
```
|
323
|
+
|
324
|
+
I have benchmarked the `JSON-Generator` as well. This generated a few more
|
325
|
+
values, because there are different modes that also influence the achieved
|
326
|
+
speed:
|
327
|
+
|
328
|
+
```
|
329
|
+
Comparing times (call_time_mean):
|
330
|
+
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
331
|
+
547.354332608 ( real) -> 15.090x
|
332
|
+
0.001826970
|
333
|
+
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
334
|
+
443.968212317 ( real) -> 12.240x
|
335
|
+
0.002252414
|
336
|
+
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
337
|
+
375.104545883 ( real) -> 10.341x
|
338
|
+
0.002665923
|
339
|
+
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
340
|
+
49.978706968 ( real) -> 1.378x
|
341
|
+
0.020008521
|
342
|
+
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
343
|
+
38.531868759 ( real) -> 1.062x
|
344
|
+
0.025952543
|
345
|
+
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
346
|
+
36.927649925 ( real) -> 1.018x 7 (>=3859)
|
347
|
+
0.027079979
|
348
|
+
7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
349
|
+
36.272134441 ( real) -> 1.000x 6 (>=3859)
|
350
|
+
0.027569373
|
351
|
+
calls/sec ( time) -> speed covers
|
352
|
+
secs/call
|
353
|
+
```
|
354
|
+
|
355
|
+
In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
|
356
|
+
`JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
|
357
|
+
bit faster than the `generator_safe` and `generator_pretty` methods of the pure
|
358
|
+
variant but slower than the others.
|
359
|
+
|
360
|
+
To achieve the fastest JSON document output, you can use the `fast_generate`
|
361
|
+
method. Beware, that this will disable the checking for circular Ruby data
|
362
|
+
structures, which may cause JSON to go into an infinite loop.
|
363
|
+
|
364
|
+
Here are the median comparisons for completeness' sake:
|
365
|
+
|
366
|
+
```
|
367
|
+
Comparing times (call_time_median):
|
368
|
+
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
369
|
+
708.258020939 ( real) -> 16.547x
|
370
|
+
0.001411915
|
371
|
+
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
372
|
+
569.105020353 ( real) -> 13.296x
|
373
|
+
0.001757145
|
374
|
+
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
375
|
+
482.825371244 ( real) -> 11.280x
|
376
|
+
0.002071142
|
377
|
+
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
378
|
+
62.717626652 ( real) -> 1.465x
|
379
|
+
0.015944481
|
380
|
+
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
381
|
+
43.965681162 ( real) -> 1.027x
|
382
|
+
0.022745013
|
383
|
+
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
384
|
+
43.929073409 ( real) -> 1.026x 7 (>=3859)
|
385
|
+
0.022763968
|
386
|
+
7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
387
|
+
42.802514491 ( real) -> 1.000x 6 (>=3859)
|
388
|
+
0.023363113
|
389
|
+
calls/sec ( time) -> speed covers
|
390
|
+
secs/call
|
391
|
+
```
|
392
|
+
|
393
|
+
## Development
|
394
|
+
|
395
|
+
### Release
|
396
|
+
|
397
|
+
Update the json.gemspec and json-java.gemspec.
|
398
|
+
|
399
|
+
```
|
400
|
+
rbenv shell 2.6.5
|
401
|
+
rake build
|
402
|
+
gem push pkg/json-2.3.0.gem
|
403
|
+
|
404
|
+
rbenv shell jruby-9.2.9.0
|
405
|
+
rake build
|
406
|
+
gem push pkg/json-2.3.0-java.gem
|
407
|
+
```
|
408
|
+
|
409
|
+
## Author
|
410
|
+
|
411
|
+
Florian Frank <mailto:flori@ping.de>
|
412
|
+
|
413
|
+
## License
|
414
|
+
|
415
|
+
Ruby License, see https://www.ruby-lang.org/en/about/license.txt.
|
416
|
+
|
417
|
+
## Download
|
418
|
+
|
419
|
+
The latest version of this library can be downloaded at
|
420
|
+
|
421
|
+
* https://rubygems.org/gems/json
|
422
|
+
|
423
|
+
Online Documentation should be located at
|
424
|
+
|
425
|
+
* https://www.rubydoc.info/gems/json
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.6.0
|
@@ -12,9 +12,6 @@
|
|
12
12
|
#define RFLOAT_VALUE(val) (RFLOAT(val)->value)
|
13
13
|
#endif
|
14
14
|
|
15
|
-
#ifndef RARRAY_PTR
|
16
|
-
#define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
|
17
|
-
#endif
|
18
15
|
#ifndef RARRAY_LEN
|
19
16
|
#define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
|
20
17
|
#endif
|
@@ -25,6 +22,15 @@
|
|
25
22
|
#define RSTRING_LEN(string) RSTRING(string)->len
|
26
23
|
#endif
|
27
24
|
|
25
|
+
#ifdef PRIsVALUE
|
26
|
+
# define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
|
27
|
+
# define RB_OBJ_STRING(obj) (obj)
|
28
|
+
#else
|
29
|
+
# define PRIsVALUE "s"
|
30
|
+
# define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
|
31
|
+
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
|
32
|
+
#endif
|
33
|
+
|
28
34
|
#ifdef HAVE_RUBY_ENCODING_H
|
29
35
|
#include "ruby/encoding.h"
|
30
36
|
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
|
@@ -172,7 +178,7 @@ static FBuffer *fbuffer_dup(FBuffer *fb)
|
|
172
178
|
|
173
179
|
static VALUE fbuffer_to_s(FBuffer *fb)
|
174
180
|
{
|
175
|
-
VALUE result = rb_str_new(
|
181
|
+
VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
|
176
182
|
fbuffer_free(fb);
|
177
183
|
FORCE_UTF8(result);
|
178
184
|
return result;
|
@@ -1,14 +1,4 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
-
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
4
|
-
$CFLAGS << ' -O3'
|
5
|
-
end
|
6
|
-
if CONFIG['CC'] =~ /gcc/
|
7
|
-
$CFLAGS << ' -Wall'
|
8
|
-
unless $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
9
|
-
$CFLAGS << ' -O0 -ggdb'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
3
|
$defs << "-DJSON_GENERATOR"
|
14
4
|
create_makefile 'json/ext/generator'
|