json 1.8.3 → 2.5.1
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} +241 -90
- data/Gemfile +10 -6
- data/{COPYING-json-jruby → LICENSE} +5 -6
- data/{README.rdoc → README.md} +201 -134
- data/VERSION +1 -1
- data/ext/json/ext/fbuffer/fbuffer.h +0 -3
- data/ext/json/ext/generator/generator.c +264 -104
- data/ext/json/ext/generator/generator.h +12 -4
- data/ext/json/ext/parser/extconf.rb +28 -0
- data/ext/json/ext/parser/parser.c +425 -462
- data/ext/json/ext/parser/parser.h +5 -5
- data/ext/json/ext/parser/parser.rl +181 -181
- data/ext/json/extconf.rb +1 -1
- data/json.gemspec +0 -0
- data/lib/json.rb +550 -29
- data/lib/json/add/bigdecimal.rb +3 -2
- data/lib/json/add/complex.rb +4 -4
- 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 +3 -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 +1 -1
- data/lib/json/common.rb +381 -162
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +5 -4
- data/lib/json/pure.rb +2 -8
- data/lib/json/pure/generator.rb +83 -126
- data/lib/json/pure/parser.rb +62 -84
- data/lib/json/version.rb +2 -1
- data/tests/fixtures/fail29.json +1 -0
- data/tests/fixtures/fail30.json +1 -0
- data/tests/fixtures/fail31.json +1 -0
- data/tests/fixtures/fail32.json +1 -0
- data/tests/fixtures/obsolete_fail1.json +1 -0
- data/tests/{test_json_addition.rb → json_addition_test.rb} +28 -25
- data/tests/json_common_interface_test.rb +169 -0
- data/tests/json_encoding_test.rb +107 -0
- data/tests/json_ext_parser_test.rb +15 -0
- data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +13 -8
- data/tests/{test_json_generate.rb → json_generator_test.rb} +109 -47
- data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
- data/tests/json_parser_test.rb +497 -0
- data/tests/json_string_matching_test.rb +38 -0
- data/tests/lib/core_assertions.rb +763 -0
- data/tests/lib/envutil.rb +365 -0
- data/tests/lib/find_executable.rb +22 -0
- data/tests/lib/helper.rb +4 -0
- data/tests/ractor_test.rb +30 -0
- data/tests/test_helper.rb +17 -0
- metadata +48 -76
- data/.gitignore +0 -16
- data/.travis.yml +0 -26
- data/COPYING +0 -58
- data/GPL +0 -340
- data/README-json-jruby.markdown +0 -33
- 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 -2645
- data/java/src/json/ext/Parser.rl +0 -969
- 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 -40
- data/tests/fixtures/fail1.json +0 -1
- data/tests/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -553
- data/tests/test_json_encoding.rb +0 -65
- 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/Gemfile
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
|
3
3
|
source 'https://rubygems.org'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
version 2 (see the file GPL), or the conditions below:
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
5
4
|
|
6
5
|
1. You may make and give away verbatim copies of the source form of the
|
7
6
|
software without restriction, provided that you duplicate all of the
|
@@ -45,9 +44,9 @@ version 2 (see the file GPL), or the conditions below:
|
|
45
44
|
For the list of those files and their copying conditions, see the
|
46
45
|
file LEGAL.
|
47
46
|
|
48
|
-
5. The scripts and library files supplied as input to or produced as
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
49
48
|
output from the software do not automatically fall under the
|
50
|
-
copyright of the software, but belong to whomever generated them,
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
51
50
|
and may be sold commercially, and may be aggregated with this
|
52
51
|
software.
|
53
52
|
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
# JSON implementation for Ruby
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/flori/json)
|
4
4
|
|
5
|
-
|
6
|
-
|
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
|
7
9
|
will be two variants available:
|
8
10
|
|
9
11
|
* A pure ruby variant, that relies on the iconv and the stringscan
|
@@ -11,28 +13,21 @@ will be two variants available:
|
|
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
15
|
functions and a parser generated by the ragel state machine compiler
|
14
|
-
http://www.
|
16
|
+
http://www.complang.org/ragel/ .
|
15
17
|
|
16
18
|
Both variants of the JSON generator generate UTF-8 character sequences by
|
17
|
-
default. If an :
|
19
|
+
default. If an :ascii\_only option with a true value is given, they escape all
|
18
20
|
non-ASCII and control characters with \uXXXX escape sequences, and support
|
19
21
|
UTF-16 surrogate pairs in order to be able to generate the whole range of
|
20
22
|
unicode code points.
|
21
23
|
|
22
24
|
All strings, that are to be encoded as JSON strings, should be UTF-8 byte
|
23
25
|
sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
|
24
|
-
encoded, please use the
|
26
|
+
encoded, please use the to\_json\_raw\_object method of String (which produces
|
25
27
|
an object, that contains a byte array) and decode the result on the receiving
|
26
28
|
endpoint.
|
27
29
|
|
28
|
-
|
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
|
-
== Installation
|
30
|
+
## Installation
|
36
31
|
|
37
32
|
It's recommended to use the extension variant of JSON, because it's faster than
|
38
33
|
the pure ruby variant. If you cannot build it on your system, you can settle
|
@@ -40,162 +35,211 @@ for the latter.
|
|
40
35
|
|
41
36
|
Just type into the command line as root:
|
42
37
|
|
43
|
-
|
38
|
+
```
|
39
|
+
# rake install
|
40
|
+
```
|
44
41
|
|
45
42
|
The above command will build the extensions and install them on your system.
|
46
43
|
|
47
|
-
|
44
|
+
```
|
45
|
+
# rake install_pure
|
46
|
+
```
|
48
47
|
|
49
48
|
or
|
50
49
|
|
51
|
-
|
50
|
+
```
|
51
|
+
# ruby install.rb
|
52
|
+
```
|
52
53
|
|
53
54
|
will just install the pure ruby implementation of JSON.
|
54
55
|
|
55
56
|
If you use Rubygems you can type
|
56
57
|
|
57
|
-
|
58
|
+
```
|
59
|
+
# gem install json
|
60
|
+
```
|
58
61
|
|
59
62
|
instead, to install the newest JSON version.
|
60
63
|
|
61
64
|
There is also a pure ruby json only variant of the gem, that can be installed
|
62
65
|
with:
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
```
|
68
|
+
# gem install json_pure
|
69
|
+
```
|
67
70
|
|
68
|
-
|
71
|
+
## Compiling the extensions yourself
|
69
72
|
|
70
|
-
|
71
|
-
|
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/
|
72
76
|
|
73
|
-
|
77
|
+
## Usage
|
74
78
|
|
75
|
-
|
76
|
-
|
77
|
-
for the installation via rubygems.
|
79
|
+
To use JSON you can
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
+
```ruby
|
82
|
+
require 'json'
|
83
|
+
```
|
81
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
|
82
88
|
|
83
|
-
|
89
|
+
```ruby
|
90
|
+
require 'json/ext'
|
91
|
+
```
|
84
92
|
|
85
|
-
To use JSON you can
|
86
|
-
require 'json'
|
87
|
-
to load the installed variant (either the extension 'json' or the pure
|
88
|
-
variant 'json_pure'). If you have installed the extension variant, you can
|
89
|
-
pick either the extension variant or the pure variant by typing
|
90
|
-
require 'json/ext'
|
91
93
|
or
|
92
|
-
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
require 'json/pure'
|
97
|
+
```
|
93
98
|
|
94
99
|
Now you can parse a JSON document into a ruby data structure by calling
|
95
100
|
|
96
|
-
|
101
|
+
```ruby
|
102
|
+
JSON.parse(document)
|
103
|
+
```
|
97
104
|
|
98
105
|
If you want to generate a JSON document from a ruby data structure call
|
99
|
-
|
106
|
+
```ruby
|
107
|
+
JSON.generate(data)
|
108
|
+
```
|
100
109
|
|
101
|
-
You can also use the pretty_generate method (which formats the output more
|
102
|
-
verbosely and nicely) or fast_generate (which doesn't do any of the security
|
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
|
103
112
|
checks generate performs, e. g. nesting deepness checks).
|
104
113
|
|
105
|
-
To create a valid JSON document you have to make sure, that the output is
|
106
|
-
embedded in either a JSON array [] or a JSON object {}. The easiest way to do
|
107
|
-
this, is by putting your values in a Ruby Array or Hash instance.
|
108
|
-
|
109
114
|
There are also the JSON and JSON[] methods which use parse on a String or
|
110
115
|
generate a JSON document from an array or hash:
|
111
116
|
|
112
|
-
|
113
|
-
|
117
|
+
```ruby
|
118
|
+
document = JSON 'test' => 23 # => "{\"test\":23}"
|
119
|
+
document = JSON['test' => 23] # => "{\"test\":23}"
|
120
|
+
```
|
114
121
|
|
115
122
|
and
|
116
123
|
|
117
|
-
|
118
|
-
|
124
|
+
```ruby
|
125
|
+
data = JSON '{"test":23}' # => {"test"=>23}
|
126
|
+
data = JSON['{"test":23}'] # => {"test"=>23}
|
127
|
+
```
|
119
128
|
|
120
129
|
You can choose to load a set of common additions to ruby core's objects if
|
121
130
|
you
|
122
|
-
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
require 'json/add/core'
|
134
|
+
```
|
123
135
|
|
124
136
|
After requiring this you can, e. g., serialise/deserialise Ruby ranges:
|
125
137
|
|
126
|
-
|
138
|
+
```ruby
|
139
|
+
JSON JSON(1..10) # => 1..10
|
140
|
+
```
|
127
141
|
|
128
142
|
To find out how to add JSON support to other or your own classes, read the
|
129
143
|
section "More Examples" below.
|
130
144
|
|
131
145
|
To get the best compatibility to rails' JSON implementation, you can
|
132
|
-
require 'json/add/rails'
|
133
146
|
|
134
|
-
|
147
|
+
```ruby
|
148
|
+
require 'json/add/rails'
|
149
|
+
```
|
150
|
+
|
151
|
+
Both of the additions attempt to require `'json'` (like above) first, if it has
|
135
152
|
not been required yet.
|
136
153
|
|
137
|
-
|
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
|
138
167
|
|
139
168
|
To create a JSON document from a ruby data structure, you can call
|
140
|
-
JSON.generate like that:
|
169
|
+
`JSON.generate` like that:
|
141
170
|
|
142
|
-
|
143
|
-
|
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
|
+
```
|
144
175
|
|
145
176
|
To get back a ruby data structure from a JSON document, you have to call
|
146
177
|
JSON.parse on it:
|
147
178
|
|
148
|
-
|
149
|
-
|
179
|
+
```ruby
|
180
|
+
JSON.parse json
|
181
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
182
|
+
```
|
150
183
|
|
151
184
|
Note, that the range from the original data structure is a simple
|
152
185
|
string now. The reason for this is, that JSON doesn't support ranges
|
153
186
|
or arbitrary classes. In this case the json library falls back to call
|
154
|
-
Object#to_json
|
187
|
+
`Object#to_json`, which is the same as `#to_s.to_json`.
|
155
188
|
|
156
189
|
It's possible to add JSON support serialization to arbitrary classes by
|
157
|
-
simply implementing a more specialized version of the
|
158
|
-
should return a JSON object (a hash converted to JSON with
|
159
|
-
this (don't forget the
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
173
208
|
used to store the necessary data to configure the object to be deserialised.
|
174
209
|
|
175
|
-
If
|
176
|
-
if the given class responds to the json_create class method. If so, it is
|
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
|
177
212
|
called with the JSON object converted to a Ruby hash. So a range can
|
178
|
-
be deserialised by implementing Range.json_create like this:
|
213
|
+
be deserialised by implementing `Range.json_create` like this:
|
179
214
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
215
|
+
```ruby
|
216
|
+
class Range
|
217
|
+
def self.json_create(o)
|
218
|
+
new(*o['data'])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
```
|
185
222
|
|
186
223
|
Now it possible to serialise/deserialise ranges as well:
|
187
224
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
JSON.generate
|
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
|
194
237
|
ruby data structure in one line. This is good for data storage or network
|
195
238
|
protocols, but not so good for humans to read. Fortunately there's also
|
196
|
-
JSON.pretty_generate (or JSON.pretty_generate) that creates a more readable
|
239
|
+
`JSON.pretty_generate` (or `JSON.pretty_generate`) that creates a more readable
|
197
240
|
output:
|
198
241
|
|
242
|
+
```ruby
|
199
243
|
puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
|
200
244
|
[
|
201
245
|
1,
|
@@ -215,82 +259,88 @@ output:
|
|
215
259
|
]
|
216
260
|
}
|
217
261
|
]
|
262
|
+
```
|
218
263
|
|
219
|
-
There are also the methods Kernel#j for generate, and Kernel#jj for
|
220
|
-
pretty_generate output to the console, that work analogous to Core Ruby's p and
|
221
|
-
the pp library's pp methods.
|
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.
|
222
267
|
|
223
|
-
The script tools/server.rb contains a small example if you want to test, how
|
268
|
+
The script `tools/server.rb` contains a small example if you want to test, how
|
224
269
|
receiving a JSON object from a webrick server in your browser with the
|
225
270
|
javasript prototype library http://www.prototypejs.org works.
|
226
271
|
|
227
|
-
|
272
|
+
## Speed Comparisons
|
228
273
|
|
229
274
|
I have created some benchmark results (see the benchmarks/data-p4-3Ghz
|
230
275
|
subdir of the package) for the JSON-parser to estimate the speed up in the C
|
231
276
|
extension:
|
232
277
|
|
278
|
+
```
|
233
279
|
Comparing times (call_time_mean):
|
234
280
|
1 ParserBenchmarkExt#parser 900 repeats:
|
235
|
-
553.922304770 ( real) -> 21.500x
|
281
|
+
553.922304770 ( real) -> 21.500x
|
236
282
|
0.001805307
|
237
283
|
2 ParserBenchmarkYAML#parser 1000 repeats:
|
238
|
-
224.513358139 ( real) -> 8.714x
|
284
|
+
224.513358139 ( real) -> 8.714x
|
239
285
|
0.004454078
|
240
286
|
3 ParserBenchmarkPure#parser 1000 repeats:
|
241
|
-
26.755020642 ( real) -> 1.038x
|
287
|
+
26.755020642 ( real) -> 1.038x
|
242
288
|
0.037376163
|
243
289
|
4 ParserBenchmarkRails#parser 1000 repeats:
|
244
|
-
25.763381731 ( real) -> 1.000x
|
290
|
+
25.763381731 ( real) -> 1.000x
|
245
291
|
0.038814780
|
246
292
|
calls/sec ( time) -> speed covers
|
247
293
|
secs/call
|
294
|
+
```
|
248
295
|
|
249
|
-
In the table above 1 is JSON::Ext::Parser
|
250
|
-
compatbile JSON document, 3 is is JSON::Pure::Parser
|
251
|
-
ActiveSupport::JSON.decode
|
296
|
+
In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
|
297
|
+
compatbile JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
|
298
|
+
`ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
|
252
299
|
input first to YAML and then uses the YAML-parser, the conversion seems to
|
253
|
-
slow it down so much that it is only as fast as the JSON::Pure::Parser
|
300
|
+
slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
|
254
301
|
|
255
302
|
If you look at the benchmark data you can see that this is mostly caused by
|
256
303
|
the frequent high outliers - the median of the Rails-parser runs is still
|
257
|
-
overall smaller than the median of the JSON::Pure::Parser runs:
|
304
|
+
overall smaller than the median of the `JSON::Pure::Parser` runs:
|
258
305
|
|
306
|
+
```
|
259
307
|
Comparing times (call_time_median):
|
260
308
|
1 ParserBenchmarkExt#parser 900 repeats:
|
261
|
-
800.592479481 ( real) -> 26.936x
|
309
|
+
800.592479481 ( real) -> 26.936x
|
262
310
|
0.001249075
|
263
311
|
2 ParserBenchmarkYAML#parser 1000 repeats:
|
264
|
-
271.002390644 ( real) -> 9.118x
|
312
|
+
271.002390644 ( real) -> 9.118x
|
265
313
|
0.003690004
|
266
314
|
3 ParserBenchmarkRails#parser 1000 repeats:
|
267
|
-
30.227910865 ( real) -> 1.017x
|
315
|
+
30.227910865 ( real) -> 1.017x
|
268
316
|
0.033082008
|
269
317
|
4 ParserBenchmarkPure#parser 1000 repeats:
|
270
|
-
29.722384421 ( real) -> 1.000x
|
318
|
+
29.722384421 ( real) -> 1.000x
|
271
319
|
0.033644676
|
272
320
|
calls/sec ( time) -> speed covers
|
273
321
|
secs/call
|
322
|
+
```
|
274
323
|
|
275
|
-
I have benchmarked the JSON-Generator as well. This generated a few more
|
324
|
+
I have benchmarked the `JSON-Generator` as well. This generated a few more
|
276
325
|
values, because there are different modes that also influence the achieved
|
277
326
|
speed:
|
278
327
|
|
328
|
+
```
|
279
329
|
Comparing times (call_time_mean):
|
280
330
|
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
281
|
-
547.354332608 ( real) -> 15.090x
|
331
|
+
547.354332608 ( real) -> 15.090x
|
282
332
|
0.001826970
|
283
333
|
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
284
|
-
443.968212317 ( real) -> 12.240x
|
334
|
+
443.968212317 ( real) -> 12.240x
|
285
335
|
0.002252414
|
286
336
|
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
287
|
-
375.104545883 ( real) -> 10.341x
|
337
|
+
375.104545883 ( real) -> 10.341x
|
288
338
|
0.002665923
|
289
339
|
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
290
|
-
49.978706968 ( real) -> 1.378x
|
340
|
+
49.978706968 ( real) -> 1.378x
|
291
341
|
0.020008521
|
292
342
|
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
293
|
-
38.531868759 ( real) -> 1.062x
|
343
|
+
38.531868759 ( real) -> 1.062x
|
294
344
|
0.025952543
|
295
345
|
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
296
346
|
36.927649925 ( real) -> 1.018x 7 (>=3859)
|
@@ -300,33 +350,35 @@ speed:
|
|
300
350
|
0.027569373
|
301
351
|
calls/sec ( time) -> speed covers
|
302
352
|
secs/call
|
353
|
+
```
|
303
354
|
|
304
|
-
In the table above 1-3 are JSON::Ext::Generator methods. 4, 6, and 7 are
|
305
|
-
JSON::Pure::Generator methods and 5 is the Rails JSON generator. It is now a
|
306
|
-
bit faster than the generator_safe and generator_pretty methods of the pure
|
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
|
307
358
|
variant but slower than the others.
|
308
359
|
|
309
|
-
To achieve the fastest JSON document output, you can use the fast_generate
|
360
|
+
To achieve the fastest JSON document output, you can use the `fast_generate`
|
310
361
|
method. Beware, that this will disable the checking for circular Ruby data
|
311
362
|
structures, which may cause JSON to go into an infinite loop.
|
312
363
|
|
313
364
|
Here are the median comparisons for completeness' sake:
|
314
365
|
|
366
|
+
```
|
315
367
|
Comparing times (call_time_median):
|
316
368
|
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
317
|
-
708.258020939 ( real) -> 16.547x
|
369
|
+
708.258020939 ( real) -> 16.547x
|
318
370
|
0.001411915
|
319
371
|
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
320
|
-
569.105020353 ( real) -> 13.296x
|
372
|
+
569.105020353 ( real) -> 13.296x
|
321
373
|
0.001757145
|
322
374
|
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
323
|
-
482.825371244 ( real) -> 11.280x
|
375
|
+
482.825371244 ( real) -> 11.280x
|
324
376
|
0.002071142
|
325
377
|
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
326
|
-
62.717626652 ( real) -> 1.465x
|
378
|
+
62.717626652 ( real) -> 1.465x
|
327
379
|
0.015944481
|
328
380
|
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
329
|
-
43.965681162 ( real) -> 1.027x
|
381
|
+
43.965681162 ( real) -> 1.027x
|
330
382
|
0.022745013
|
331
383
|
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
332
384
|
43.929073409 ( real) -> 1.026x 7 (>=3859)
|
@@ -336,23 +388,38 @@ Here are the median comparisons for completeness' sake:
|
|
336
388
|
0.023363113
|
337
389
|
calls/sec ( time) -> speed covers
|
338
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
|
+
```
|
339
408
|
|
340
|
-
|
409
|
+
## Author
|
341
410
|
|
342
411
|
Florian Frank <mailto:flori@ping.de>
|
343
412
|
|
344
|
-
|
413
|
+
## License
|
345
414
|
|
346
|
-
Ruby License, see
|
347
|
-
Ruby License includes the GNU General Public License (GPL), Version 2, so see
|
348
|
-
the file GPL as well.
|
415
|
+
Ruby License, see https://www.ruby-lang.org/en/about/license.txt.
|
349
416
|
|
350
|
-
|
417
|
+
## Download
|
351
418
|
|
352
419
|
The latest version of this library can be downloaded at
|
353
420
|
|
354
|
-
*
|
421
|
+
* https://rubygems.org/gems/json
|
355
422
|
|
356
423
|
Online Documentation should be located at
|
357
424
|
|
358
|
-
*
|
425
|
+
* https://www.rubydoc.info/gems/json
|