json_pure 2.7.0 → 2.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77e458393f6a12f043ff7acf7aca6f70409158bf1ebe613f009f88551da32295
4
- data.tar.gz: cabc5299a4f77bf82eb7077d3048433bbb1a3bffbd2d3c1b95385712614423ef
3
+ metadata.gz: f15ef81b6948a3ad8be4077975b9301dc8efde70ec0d8c2d834693f28bc7ab71
4
+ data.tar.gz: 41519748aa9a0f745355bf17a1c9729b68a73853c0367b9c0be3f2b88ec1b2c2
5
5
  SHA512:
6
- metadata.gz: 8ab9bf253868c6a6f637b85bc1ef432c289b733e0f41086e4a9a4a9a27fb63ebef4f7b15adb1a8792f7486f010080e9c2f902d8efaeedbb0fd2575e744e5b167
7
- data.tar.gz: a1e77e1df8e8d219a7a88fc62160d1748f19ff4cc29120cba136114370920021216ae9e9b761391c90158566d4601d70005c4df18ae145a00b47f6803e6dca5d
6
+ metadata.gz: 1e67f4395d33a86c8f894340f378aad30ac19d4922a6b341ff8fb2f9e24b74628243d81f710e7218819c03578b031ecc6bb1f2c9ceb76b2237809a97113e3299
7
+ data.tar.gz: 9dd6a6cd837441aa7314f959c0b0ef96cf3c853f1934a1da391fb3a20752340febbc9bb4c1dca5043c788b53ca791865529783e42bf3ebeb38ca0b0d811a88dc
data/BSDL ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/CHANGES.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # Changes
2
2
 
3
+ ### UNRELEASED
4
+
5
+ * Emit a deprecation warning when `JSON.load` create custom types without the `create_additions` option being explictly enabled.
6
+ * Prefer to use `JSON.unsafe_load(string)` or `JSON.load(string, create_additions: true)`.
7
+ * Emit a deprecation warning when serializing valid UTF-8 strings encoded in `ASCII_8BIT` aka `BINARY`.
8
+ * Bump required_ruby_version to 2.7.
9
+ * More performance improvments to `JSON.dump` and `JSON.generate`.
10
+
11
+ ### 2024-10-25 (2.7.5)
12
+
13
+ * Fix a memory leak when `#to_json` methods raise an exception.
14
+ * Gracefully handle formatting configs being set to `nil` instead of `""`.
15
+ * Workaround another issue caused by conflicting versions of both `json_pure` and `json` being loaded.
16
+
17
+ ### 2024-10-25 (2.7.4)
18
+
19
+ * Workaround a bug in 3.4.8 and older https://github.com/rubygems/rubygems/pull/6490.
20
+ This bug would cause some gems with native extension to fail during compilation.
21
+ * Workaround different versions of `json` and `json_pure` being loaded (not officially supported).
22
+ * Make `json_pure` Ractor compatible.
23
+
24
+ ### 2024-10-24 (2.7.3)
25
+
26
+ * Numerous performance optimizations in `JSON.generate` and `JSON.dump` (up to 2 times faster).
27
+ * Limit the size of ParserError exception messages, only include up to 32 bytes of the unparseable source.
28
+ * Fix json-pure's `Object#to_json` to accept non state arguments
29
+ * Fix multiline comment support in `json-pure`.
30
+ * Fix `JSON.parse` to no longer mutate the argument encoding when passed an ASCII-8BIT string.
31
+ * Fix `String#to_json` to raise on invalid encoding in `json-pure`.
32
+ * Delete code that was based on CVTUTF.
33
+ * Use the pure-Ruby generator on TruffleRuby.
34
+ * Fix `strict` mode in `json-pure` to not break on Integer.
35
+
36
+ ### 2024-04-04 (2.7.2)
37
+
38
+ * Use rb_sym2str instead of SYM2ID #561
39
+ * Fix memory leak when exception is raised during JSON generation #574
40
+ * Remove references to "19" methods in JRuby #576
41
+ * Make OpenStruct support as optional by @hsbt in #565
42
+ * Autoload JSON::GenericObject to avoid require ostruct warning in Ruby 3.4 #577
43
+ * Warn to install ostruct if json couldn't load it by @hsbt #578
44
+
45
+ ### 2023-12-05 (2.7.1)
46
+
47
+ * JSON.dump: handle unenclosed hashes regression #554
48
+ * Overload kwargs in JSON.dump #556
49
+ * [DOC] RDoc for additions #557
50
+ * Fix JSON.dump overload combination #558
51
+
3
52
  ### 2023-12-01 (2.7.0)
4
53
 
5
54
  * Add a strict option to Generator #519
@@ -161,7 +210,7 @@
161
210
  * Remove Rubinius exception since transcoding should be working now.
162
211
 
163
212
  ## 2013-05-13 (1.8.0)
164
- * Fix https://github.com/flori/json/issues/162 reported by Marc-Andre
213
+ * Fix https://github.com/ruby/json/issues/162 reported by Marc-Andre
165
214
  Lafortune <github_rocks@marc-andre.ca>. Thanks!
166
215
  * Applied patches by Yui NARUSE <naruse@airemix.jp> to suppress warning with
167
216
  -Wchar-subscripts and better validate UTF-8 strings.
@@ -181,7 +230,7 @@
181
230
  JSON::GenericObject.json_creatable = true
182
231
  as well.
183
232
  * Remove useless assert in fbuffer implementation.
184
- * Apply patch attached to https://github.com/flori/json/issues#issue/155
233
+ * Apply patch attached to https://github.com/ruby/json/issues#issue/155
185
234
  provided by John Shahid <jvshahid@gmail.com>, Thx!
186
235
  * Add license information to rubygems spec data, reported by Jordi Massaguer Pla <jmassaguerpla@suse.de>.
187
236
  * Improve documentation, thx to Zachary Scott <zachary@zacharyscott.net>.
@@ -195,7 +244,7 @@
195
244
  * Fix compilation of extension on older rubies.
196
245
 
197
246
  ## 2012-07-26 (1.7.4)
198
- * Fix compilation problem on AIX, see https://github.com/flori/json/issues/142
247
+ * Fix compilation problem on AIX, see https://github.com/ruby/json/issues/142
199
248
 
200
249
  ## 2012-05-12 (1.7.3)
201
250
  * Work around Rubinius encoding issues using iconv for conversion instead.
@@ -217,9 +266,9 @@
217
266
  * Propagate src encoding to values made from it (fixes 1.9 mode converting
218
267
  everything to ascii-8bit; harmless for 1.8 mode too) (Thomas E. Enebo
219
268
  <tom.enebo@gmail.com>), should fix
220
- https://github.com/flori/json/issues#issue/119.
221
- * Fix https://github.com/flori/json/issues#issue/124 Thx to Jason Hutchens.
222
- * Fix https://github.com/flori/json/issues#issue/117
269
+ https://github.com/ruby/json/issues#issue/119.
270
+ * Fix https://github.com/ruby/json/issues#issue/124 Thx to Jason Hutchens.
271
+ * Fix https://github.com/ruby/json/issues#issue/117
223
272
 
224
273
  ## 2012-01-15 (1.6.5)
225
274
  * Vit Ondruch <v.ondruch@tiscali.cz> reported a bug that shows up when using
@@ -246,7 +295,7 @@
246
295
  patch go to Josh Partlow (jpartlow@github).
247
296
  * Improve parsing speed for JSON numbers (integers and floats) in a similar way to
248
297
  what Evan Phoenix <evan@phx.io> suggested in:
249
- https://github.com/flori/json/pull/103
298
+ https://github.com/ruby/json/pull/103
250
299
 
251
300
  ## 2011-09-18 (1.6.1)
252
301
  * Using -target 1.5 to force Java bits to compile with 1.5.
@@ -259,15 +308,14 @@
259
308
  * Fix memory leak when used from multiple JRuby. (Patch by
260
309
  jfirebaugh@github).
261
310
  * Apply patch by Eric Wong <nocode@yhbt.net> that fixes garbage collection problem
262
- reported in https://github.com/flori/json/issues/46.
311
+ reported in https://github.com/ruby/json/issues/46.
263
312
  * Add :quirks_mode option to parser and generator.
264
313
  * Add support for Rational and Complex number additions via json/add/complex
265
314
  and json/add/rational requires.
266
315
 
267
316
  ## 2011-06-20 (1.5.3)
268
317
  * Alias State#configure method as State#merge to increase duck type synonymy with Hash.
269
- * Add `as_json` methods in json/add/core, so rails can create its json objects
270
- the new way.
318
+ * Add `as_json` methods in json/add/core, so rails can create its json objects the new way.
271
319
 
272
320
  ## 2011-05-11 (1.5.2)
273
321
  * Apply documentation patch by Cory Monty <cory.monty@gmail.com>.
@@ -278,7 +326,7 @@
278
326
 
279
327
  ## 2011-01-24 (1.5.1)
280
328
  * Made rake-compiler build a fat binary gem. This should fix issue
281
- https://github.com/flori/json/issues#issue/54.
329
+ https://github.com/ruby/json/issues#issue/54.
282
330
 
283
331
  ## 2011-01-22 (1.5.0)
284
332
  * Included Java source codes for the Jruby extension made by Daniel Luz
@@ -288,7 +336,7 @@
288
336
  reported by Riley Goodside.
289
337
 
290
338
  ## 2010-08-09 (1.4.6)
291
- * Fixed oversight reported in http://github.com/flori/json/issues/closed#issue/23,
339
+ * Fixed oversight reported in http://github.com/ruby/json/issues/closed#issue/23,
292
340
  always create a new object from the state prototype.
293
341
  * Made pure and ext api more similar again.
294
342
 
@@ -298,12 +346,12 @@
298
346
  argument.
299
347
  * Some fixes in the state objects and additional tests.
300
348
  ## 2010-08-06 (1.4.4)
301
- * Fixes build problem for rubinius under OS X, http://github.com/flori/json/issues/closed#issue/25
302
- * Fixes crashes described in http://github.com/flori/json/issues/closed#issue/21 and
303
- http://github.com/flori/json/issues/closed#issue/23
349
+ * Fixes build problem for rubinius under OS X, http://github.com/ruby/json/issues/closed#issue/25
350
+ * Fixes crashes described in http://github.com/ruby/json/issues/closed#issue/21 and
351
+ http://github.com/ruby/json/issues/closed#issue/23
304
352
  ## 2010-05-05 (1.4.3)
305
353
  * Fixed some test assertions, from Ruby r27587 and r27590, patch by nobu.
306
- * Fixed issue http://github.com/flori/json/issues/#issue/20 reported by
354
+ * Fixed issue http://github.com/ruby/json/issues/#issue/20 reported by
307
355
  electronicwhisper@github. Thx!
308
356
 
309
357
  ## 2010-04-26 (1.4.2)
@@ -325,7 +373,7 @@
325
373
  * Extension should at least be compatible with MRI, YARV and Rubinius.
326
374
 
327
375
  ## 2010-04-07 (1.2.4)
328
- * Triger const_missing callback to make Rails' dynamic class loading work.
376
+ * Trigger const_missing callback to make Rails' dynamic class loading work.
329
377
 
330
378
  ## 2010-03-11 (1.2.3)
331
379
  * Added a `State#[]` method which returns an attribute's value in order to
data/LEGAL ADDED
@@ -0,0 +1,60 @@
1
+ # -*- rdoc -*-
2
+
3
+ = LEGAL NOTICE INFORMATION
4
+ --------------------------
5
+
6
+ All the files in this distribution are covered under either the Ruby's
7
+ license (see the file COPYING) or public-domain except some files
8
+ mentioned below.
9
+
10
+ == MIT License
11
+ >>>
12
+ Permission is hereby granted, free of charge, to any person obtaining
13
+ a copy of this software and associated documentation files (the
14
+ "Software"), to deal in the Software without restriction, including
15
+ without limitation the rights to use, copy, modify, merge, publish,
16
+ distribute, sublicense, and/or sell copies of the Software, and to
17
+ permit persons to whom the Software is furnished to do so, subject to
18
+ the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be
21
+ included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+
31
+ == Old-style BSD license
32
+ >>>
33
+ Redistribution and use in source and binary forms, with or without
34
+ modification, are permitted provided that the following conditions
35
+ are met:
36
+ 1. Redistributions of source code must retain the above copyright
37
+ notice, this list of conditions and the following disclaimer.
38
+ 2. Redistributions in binary form must reproduce the above copyright
39
+ notice, this list of conditions and the following disclaimer in the
40
+ documentation and/or other materials provided with the distribution.
41
+ 3. Neither the name of the University nor the names of its contributors
42
+ may be used to endorse or promote products derived from this software
43
+ without specific prior written permission.
44
+
45
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55
+ SUCH DAMAGE.
56
+
57
+ IMPORTANT NOTE::
58
+
59
+ From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
60
+ paragraph 3 above is now null and void.
data/README.md CHANGED
@@ -1,21 +1,14 @@
1
1
  # JSON implementation for Ruby
2
2
 
3
- [![CI](https://github.com/flori/json/actions/workflows/ci.yml/badge.svg)](https://github.com/flori/json/actions/workflows/ci.yml)
3
+ [![CI](https://github.com/ruby/json/actions/workflows/ci.yml/badge.svg)](https://github.com/ruby/json/actions/workflows/ci.yml)
4
4
 
5
5
  ## Description
6
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:
7
+ This is an implementation of the JSON specification according to RFC 7159
8
+ http://www.ietf.org/rfc/rfc7159.txt .
10
9
 
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
-
17
- Both variants of the JSON generator generate UTF-8 character sequences by
18
- default. If an :ascii\_only option with a true value is given, they escape all
10
+ The JSON generator generate UTF-8 character sequences by default.
11
+ If an :ascii\_only option with a true value is given, they escape all
19
12
  non-ASCII and control characters with \uXXXX escape sequences, and support
20
13
  UTF-16 surrogate pairs in order to be able to generate the whole range of
21
14
  unicode code points.
@@ -32,45 +25,19 @@ It's recommended to use the extension variant of JSON, because it's faster than
32
25
  the pure ruby variant. If you cannot build it on your system, you can settle
33
26
  for the latter.
34
27
 
35
- Just type into the command line as root:
28
+ Install the gem and add to the application's Gemfile by executing:
36
29
 
37
- ```
38
- # rake install
39
- ```
30
+ $ bundle add json
40
31
 
41
- The above command will build the extensions and install them on your system.
32
+ If bundler is not being used to manage dependencies, install the gem by executing:
42
33
 
43
- ```
44
- # rake install_pure
45
- ```
34
+ $ gem install json
46
35
 
47
- or
48
-
49
- ```
50
- # ruby install.rb
51
- ```
52
-
53
- will just install the pure ruby implementation of JSON.
54
-
55
- If you use Rubygems you can type
56
-
57
- ```
58
- # gem install json
59
- ```
60
-
61
- instead, to install the newest JSON version.
62
36
 
63
37
  There is also a pure ruby json only variant of the gem, that can be installed
64
38
  with:
65
39
 
66
- ```
67
- # gem install json_pure
68
- ```
69
-
70
- ## Compiling the extensions yourself
71
-
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].
40
+ $ gem install json_pure
74
41
 
75
42
  ## Usage
76
43
 
@@ -109,59 +76,11 @@ You can also use the `pretty_generate` method (which formats the output more
109
76
  verbosely and nicely) or `fast_generate` (which doesn't do any of the security
110
77
  checks generate performs, e. g. nesting deepness checks).
111
78
 
112
- There are also the JSON and JSON[] methods which use parse on a String or
113
- generate a JSON document from an array or hash:
114
-
115
- ```ruby
116
- document = JSON 'test' => 23 # => "{\"test\":23}"
117
- document = JSON['test' => 23] # => "{\"test\":23}"
118
- ```
119
-
120
- and
121
-
122
- ```ruby
123
- data = JSON '{"test":23}' # => {"test"=>23}
124
- data = JSON['{"test":23}'] # => {"test"=>23}
125
- ```
126
-
127
- You can choose to load a set of common additions to ruby core's objects if
128
- you
129
-
130
- ```ruby
131
- require 'json/add/core'
132
- ```
133
-
134
- After requiring this you can, e. g., serialise/deserialise Ruby ranges:
135
-
136
- ```ruby
137
- JSON JSON(1..10) # => 1..10
138
- ```
79
+ ## Handling arbitrary types
139
80
 
140
- To find out how to add JSON support to other or your own classes, read the
141
- section "More Examples" below.
142
-
143
- To get the best compatibility to rails' JSON implementation, you can
144
-
145
- ```ruby
146
- require 'json/add/rails'
147
- ```
148
-
149
- Both of the additions attempt to require `'json'` (like above) first, if it has
150
- not been required yet.
151
-
152
- ## Serializing exceptions
153
-
154
- The JSON module doesn't extend `Exception` by default. If you convert an `Exception`
155
- object to JSON, it will by default only include the exception message.
156
-
157
- To include the full details, you must either load the `json/add/core` mentioned
158
- above, or specifically load the exception addition:
159
-
160
- ```ruby
161
- require 'json/add/exception'
162
- ```
163
-
164
- ## More Examples
81
+ > [!CAUTION]
82
+ > You should never use `JSON.unsafe_load` nor `JSON.parse(str, create_additions: true)` to parse untrusted user input,
83
+ > as it can lead to remove code execution vulnerabilities.
165
84
 
166
85
  To create a JSON document from a ruby data structure, you can call
167
86
  `JSON.generate` like that:
@@ -227,7 +146,7 @@ JSON.parse json
227
146
  # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
228
147
  json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
229
148
  # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
230
- JSON.parse json, :create_additions => true
149
+ JSON.unsafe_load json
231
150
  # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
232
151
  ```
233
152
 
@@ -263,136 +182,11 @@ There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
263
182
  `pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
264
183
  the `pp` library's `pp` methods.
265
184
 
266
- The script `tools/server.rb` contains a small example if you want to test, how
267
- receiving a JSON object from a webrick server in your browser with the
268
- JavaScript prototype library http://www.prototypejs.org works.
269
-
270
- ## Speed Comparisons
271
-
272
- I have created some benchmark results (see the benchmarks/data-p4-3Ghz
273
- subdir of the package) for the JSON-parser to estimate the speed up in the C
274
- extension:
275
-
276
- ```
277
- Comparing times (call_time_mean):
278
- 1 ParserBenchmarkExt#parser 900 repeats:
279
- 553.922304770 ( real) -> 21.500x
280
- 0.001805307
281
- 2 ParserBenchmarkYAML#parser 1000 repeats:
282
- 224.513358139 ( real) -> 8.714x
283
- 0.004454078
284
- 3 ParserBenchmarkPure#parser 1000 repeats:
285
- 26.755020642 ( real) -> 1.038x
286
- 0.037376163
287
- 4 ParserBenchmarkRails#parser 1000 repeats:
288
- 25.763381731 ( real) -> 1.000x
289
- 0.038814780
290
- calls/sec ( time) -> speed covers
291
- secs/call
292
- ```
293
-
294
- In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
295
- compatible JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
296
- `ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
297
- input first to YAML and then uses the YAML-parser, the conversion seems to
298
- slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
299
-
300
- If you look at the benchmark data you can see that this is mostly caused by
301
- the frequent high outliers - the median of the Rails-parser runs is still
302
- overall smaller than the median of the `JSON::Pure::Parser` runs:
303
-
304
- ```
305
- Comparing times (call_time_median):
306
- 1 ParserBenchmarkExt#parser 900 repeats:
307
- 800.592479481 ( real) -> 26.936x
308
- 0.001249075
309
- 2 ParserBenchmarkYAML#parser 1000 repeats:
310
- 271.002390644 ( real) -> 9.118x
311
- 0.003690004
312
- 3 ParserBenchmarkRails#parser 1000 repeats:
313
- 30.227910865 ( real) -> 1.017x
314
- 0.033082008
315
- 4 ParserBenchmarkPure#parser 1000 repeats:
316
- 29.722384421 ( real) -> 1.000x
317
- 0.033644676
318
- calls/sec ( time) -> speed covers
319
- secs/call
320
- ```
321
-
322
- I have benchmarked the `JSON-Generator` as well. This generated a few more
323
- values, because there are different modes that also influence the achieved
324
- speed:
325
-
326
- ```
327
- Comparing times (call_time_mean):
328
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
329
- 547.354332608 ( real) -> 15.090x
330
- 0.001826970
331
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
332
- 443.968212317 ( real) -> 12.240x
333
- 0.002252414
334
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
335
- 375.104545883 ( real) -> 10.341x
336
- 0.002665923
337
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
338
- 49.978706968 ( real) -> 1.378x
339
- 0.020008521
340
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
341
- 38.531868759 ( real) -> 1.062x
342
- 0.025952543
343
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
344
- 36.927649925 ( real) -> 1.018x 7 (>=3859)
345
- 0.027079979
346
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
347
- 36.272134441 ( real) -> 1.000x 6 (>=3859)
348
- 0.027569373
349
- calls/sec ( time) -> speed covers
350
- secs/call
351
- ```
352
-
353
- In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
354
- `JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
355
- bit faster than the `generator_safe` and `generator_pretty` methods of the pure
356
- variant but slower than the others.
357
-
358
- To achieve the fastest JSON document output, you can use the `fast_generate`
359
- method. Beware, that this will disable the checking for circular Ruby data
360
- structures, which may cause JSON to go into an infinite loop.
361
-
362
- Here are the median comparisons for completeness' sake:
363
-
364
- ```
365
- Comparing times (call_time_median):
366
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
367
- 708.258020939 ( real) -> 16.547x
368
- 0.001411915
369
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
370
- 569.105020353 ( real) -> 13.296x
371
- 0.001757145
372
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
373
- 482.825371244 ( real) -> 11.280x
374
- 0.002071142
375
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
376
- 62.717626652 ( real) -> 1.465x
377
- 0.015944481
378
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
379
- 43.965681162 ( real) -> 1.027x
380
- 0.022745013
381
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
382
- 43.929073409 ( real) -> 1.026x 7 (>=3859)
383
- 0.022763968
384
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
385
- 42.802514491 ( real) -> 1.000x 6 (>=3859)
386
- 0.023363113
387
- calls/sec ( time) -> speed covers
388
- secs/call
389
- ```
390
-
391
185
  ## Development
392
186
 
393
187
  ### Release
394
188
 
395
- Update the json.gemspec and json-java.gemspec.
189
+ Update the `lib/json/version.rb` file.
396
190
 
397
191
  ```
398
192
  rbenv shell 2.6.5
data/json_pure.gemspec CHANGED
@@ -1,55 +1,39 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
3
+ version = File.foreach(File.join(__dir__, "lib/json/version.rb")) do |line|
4
+ /^\s*VERSION\s*=\s*'(.*)'/ =~ line and break $1
5
+ end rescue nil
2
6
 
3
7
  Gem::Specification.new do |s|
4
- s.name = "json_pure".freeze
5
- s.version = File.read("VERSION").chomp
8
+ s.name = "json_pure"
9
+ s.version = version
6
10
 
7
- s.summary = "JSON Implementation for Ruby".freeze
8
- s.description = "This is a JSON implementation in pure Ruby.".freeze
9
- s.licenses = ["Ruby".freeze]
10
- s.authors = ["Florian Frank".freeze]
11
- s.email = "flori@ping.de".freeze
11
+ s.summary = "JSON Implementation for Ruby"
12
+ s.description = "This is a JSON implementation in pure Ruby."
13
+ s.licenses = ["Ruby"]
14
+ s.authors = ["Florian Frank"]
15
+ s.email = "flori@ping.de"
12
16
 
13
- s.extra_rdoc_files = ["README.md".freeze]
14
- s.rdoc_options = ["--title".freeze, "JSON implementation for ruby".freeze, "--main".freeze, "README.md".freeze]
17
+ s.extra_rdoc_files = ["README.md"]
18
+ s.rdoc_options = ["--title", "JSON implementation for ruby", "--main", "README.md"]
15
19
  s.files = [
16
- "CHANGES.md".freeze,
17
- "LICENSE".freeze,
18
- "README.md".freeze,
19
- "VERSION".freeze,
20
- "json_pure.gemspec".freeze,
21
- "lib/json.rb".freeze,
22
- "lib/json/add/bigdecimal.rb".freeze,
23
- "lib/json/add/complex.rb".freeze,
24
- "lib/json/add/core.rb".freeze,
25
- "lib/json/add/date.rb".freeze,
26
- "lib/json/add/date_time.rb".freeze,
27
- "lib/json/add/exception.rb".freeze,
28
- "lib/json/add/ostruct.rb".freeze,
29
- "lib/json/add/range.rb".freeze,
30
- "lib/json/add/rational.rb".freeze,
31
- "lib/json/add/regexp.rb".freeze,
32
- "lib/json/add/set.rb".freeze,
33
- "lib/json/add/struct.rb".freeze,
34
- "lib/json/add/symbol.rb".freeze,
35
- "lib/json/add/time.rb".freeze,
36
- "lib/json/common.rb".freeze,
37
- "lib/json/ext.rb".freeze,
38
- "lib/json/generic_object.rb".freeze,
39
- "lib/json/pure.rb".freeze,
40
- "lib/json/pure/generator.rb".freeze,
41
- "lib/json/pure/parser.rb".freeze,
42
- "lib/json/version.rb".freeze,
20
+ "CHANGES.md",
21
+ "COPYING",
22
+ "BSDL",
23
+ "LEGAL",
24
+ "README.md",
25
+ "json_pure.gemspec",
26
+ "lib/json/pure.rb",
43
27
  ]
44
- s.homepage = "https://flori.github.io/json".freeze
28
+ s.homepage = "https://ruby.github.io/json"
45
29
  s.metadata = {
46
- 'bug_tracker_uri' => 'https://github.com/flori/json/issues',
47
- 'changelog_uri' => 'https://github.com/flori/json/blob/master/CHANGES.md',
48
- 'documentation_uri' => 'https://flori.github.io/json/doc/index.html',
30
+ 'bug_tracker_uri' => 'https://github.com/ruby/json/issues',
31
+ 'changelog_uri' => 'https://github.com/ruby/json/blob/master/CHANGES.md',
32
+ 'documentation_uri' => 'https://ruby.github.io/json/doc/index.html',
49
33
  'homepage_uri' => s.homepage,
50
- 'source_code_uri' => 'https://github.com/flori/json',
51
- 'wiki_uri' => 'https://github.com/flori/json/wiki'
34
+ 'source_code_uri' => 'https://github.com/ruby/json',
35
+ 'wiki_uri' => 'https://github.com/ruby/json/wiki'
52
36
  }
53
37
 
54
- s.required_ruby_version = Gem::Requirement.new(">= 2.3".freeze)
38
+ s.required_ruby_version = Gem::Requirement.new(">= 2.7")
55
39
  end
data/lib/json/pure.rb CHANGED
@@ -1,15 +1,4 @@
1
- require 'json/common'
1
+ # frozen_string_literal: true
2
2
 
3
- module JSON
4
- # This module holds all the modules/classes that implement JSON's
5
- # functionality in pure ruby.
6
- module Pure
7
- require 'json/pure/parser'
8
- require 'json/pure/generator'
9
- $DEBUG and warn "Using Pure library for JSON."
10
- JSON.parser = Parser
11
- JSON.generator = Generator
12
- end
13
-
14
- JSON_LOADED = true unless defined?(::JSON::JSON_LOADED)
15
- end
3
+ warn "`json_pure` is deprecated and has no effect, just use `json`"
4
+ require "json"