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