Releases: ruby/json
Releases · ruby/json
v2.8.2
v2.8.1
- Fix the
java
version of the package to include the extension implementation. Only concerns JRuby.
Full Changelog: v2.8.0...v2.8.1
v2.8.0
What's Changed
- Emit a deprecation warning when
JSON.load
create custom types without thecreate_additions
option being explictly enabled.- Prefer to use
JSON.unsafe_load(string)
orJSON.load(string, create_additions: true)
.
- Prefer to use
- Emit a deprecation warning when serializing valid UTF-8 strings encoded in
ASCII_8BIT
akaBINARY
. - Bump required Ruby version to 2.7.
- Add support for optionally parsing trailing commas, via
allow_trailing_comma: true
, which in cunjunction with the
pre-existing support for comments, make it suitable to parsejsonc
documents. - Many performance improvements to
JSON.parse
andJSON.load
, up to1.7x
faster on real world documents. - Some minor performance improvements to
JSON.dump
andJSON.generate
.
Parsing performance
Parsing performance is improved by 50-70% on realistic benchmarks, and even more on micro-benchmarks: https://gist.github.com/casperisfine/cf4b3a0594fae24b7d0eb93daaf3841a
== Parsing activitypub.json (58160 bytes)
ruby 3.4.0dev (2024-11-06T07:59:09Z precompute-hash-wh.. 7943f98a8a) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
json 2.7.2 638.000 i/100ms
oj 798.000 i/100ms
Oj::Parser 948.000 i/100ms
rapidjson 631.000 i/100ms
Calculating -------------------------------------
json 2.7.2 6.423k (± 1.3%) i/s (155.70 μs/i) - 32.538k in 5.067149s
oj 7.989k (± 1.0%) i/s (125.17 μs/i) - 40.698k in 5.094544s
Oj::Parser 9.472k (± 1.3%) i/s (105.58 μs/i) - 47.400k in 5.005119s
rapidjson 6.354k (± 1.1%) i/s (157.37 μs/i) - 32.181k in 5.064962s
Comparison:
json 2.8.0: 9510.0 i/s
Oj::Parser: 9471.9 i/s - same-ish: difference falls within error
oj: 7989.4 i/s - 1.19x slower
json 2.7.2: 6422.5 i/s - 1.48x slower
rapidjson: 6354.5 i/s - 1.50x slower
== Parsing twitter.json (567916 bytes)
ruby 3.4.0dev (2024-11-06T07:59:09Z precompute-hash-wh.. 7943f98a8a) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
json 2.7.2 52.000 i/100ms
oj 64.000 i/100ms
Oj::Parser 76.000 i/100ms
rapidjson 57.000 i/100ms
Calculating -------------------------------------
json 2.7.2 526.860 (± 3.8%) i/s (1.90 ms/i) - 2.652k in 5.042680s
oj 631.234 (± 1.7%) i/s (1.58 ms/i) - 3.200k in 5.070973s
Oj::Parser 764.354 (± 3.5%) i/s (1.31 ms/i) - 3.876k in 5.077736s
rapidjson 579.085 (± 2.8%) i/s (1.73 ms/i) - 2.907k in 5.024620s
Comparison:
json 2.8.0: 884.0 i/s
Oj::Parser: 764.4 i/s - 1.16x slower
oj: 631.2 i/s - 1.40x slower
rapidjson: 579.1 i/s - 1.53x slower
json 2.7.2: 526.9 i/s - 1.68x slower
== Parsing citm_catalog.json (1727030 bytes)
ruby 3.4.0dev (2024-11-06T07:59:09Z precompute-hash-wh.. 7943f98a8a) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
json 2.7.2 30.000 i/100ms
oj 35.000 i/100ms
Oj::Parser 45.000 i/100ms
rapidjson 40.000 i/100ms
Calculating -------------------------------------
json 2.7.2 304.584 (± 3.3%) i/s (3.28 ms/i) - 1.530k in 5.029021s
oj 358.572 (± 0.8%) i/s (2.79 ms/i) - 1.820k in 5.076123s
Oj::Parser 450.643 (± 3.1%) i/s (2.22 ms/i) - 2.295k in 5.098150s
rapidjson 395.304 (± 1.5%) i/s (2.53 ms/i) - 2.000k in 5.060537s
Comparison:
json 2.8.0: 449.8 i/s
Oj::Parser: 450.6 i/s - same-ish: difference falls within error
rapidjson: 395.3 i/s - 1.14x slower
oj: 358.6 i/s - 1.25x slower
json 2.7.2: 304.6 i/s - 1.48x slower
Full Changelog: v2.7.3...v2.8.0
v2.7.6
- Fix a regression in JSON.generate when dealing with Hash keys that are string subclasses, call
to_json
on them.
Full Changelog: v2.7.5...v2.7.6
v2.7.5
What's Changed
- Fix a memory leak when
#to_json
methods raise an exception. - Gracefully handle formatting configs being set to
nil
instead of""
. - Workaround another issue caused by conflicting versions of both
json_pure
andjson
being loaded.
Full Changelog: v2.7.4...v2.7.5
v2.7.4
What's Changed
- Workaround a bug in 3.4.8 and older rubygems/rubygems#6490.
This bug would cause some gems with native extension to fail during compilation. - Workaround different versions of
json
andjson_pure
being loaded (not officially supported). - Make
json_pure
Ractor compatible.
Full Changelog: v2.7.3...v2.7.4
v2.7.3
What's Changed
- Numerous performance optimizations in
JSON.generate
andJSON.dump
(up to 2 times faster). - Limit the size of ParserError exception messages, only include up to 32 bytes of the unparseable source.
- Fix json-pure's
Object#to_json
to accept non state arguments - Fix multiline comment support in
json-pure
. - Fix
JSON.parse
to no longer mutate the argument encoding when passed an ASCII-8BIT string. - Fix
String#to_json
to raise on invalid encoding injson-pure
. - Delete code that was based on CVTUTF.
- Use the pure-Ruby generator on TruffleRuby.
- Fix
strict
mode injson-pure
to not break on Integer.
JSON.dump
Performance
JSON.dump
is now much faster, and on par or faster than alternative implementations:
== Encoding citm_catalog.json (500298 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json (2.7.3) 123.000 i/100ms
oj 124.000 i/100ms
Calculating -------------------------------------
json (2.7.3) 1.312k (± 1.8%) i/s (761.91 μs/i) - 6.642k in 5.062192s
oj 1.278k (± 2.0%) i/s (782.35 μs/i) - 6.448k in 5.046587s
Comparison:
json (2.7.2): 884.0 i/s
json (2.7.3): 1312.5 i/s - 1.48x faster
oj: 1278.2 i/s - 1.45x faster
== Encoding twitter.json (466906 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
json (2.7.3) 213.000 i/100ms
oj 222.000 i/100ms
Calculating -------------------------------------
json (2.7.3) 2.140k (± 2.8%) i/s (467.19 μs/i) - 10.863k in 5.079099s
oj 2.303k (± 3.2%) i/s (434.27 μs/i) - 11.544k in 5.018239s
Comparison:
json (2.7.2): 1250.5 i/s
oj: 2302.7 i/s - 1.84x faster
json (2.7.3): 2140.5 i/s - 1.71x faster
Full Changelog: v2.7.2...v2.7.3
v2.7.3.rc1
- Numerous performance optimizations in
JSON.generate
andJSON.dump
. - Limit the size of ParserError exception messages, only include up to 32 bytes of the unparseable source.
- Fix json-pure's
Object#to_json
to accept non state arguments - Fix multiline comment support in
json-pure
. - Fix
JSON.parse
to no longer mutate the argument encoding when passed an ASCII-8BIT string. - Fix
String#to_json
to raise on invalid encoding injson-pure
. - Delete code that was based on CVTUTF.
- Use the pure-Ruby generator on TruffleRuby.
- Fix
strict
mode injson-pure
to not break on Integer.
v2.7.2
What's Changed
- Use rb_sym2str instead of SYM2ID by @jhawthorn in #561
- Fix memory leak when exception is raised during JSON generation by @peterzhu2118 in #574
- Remove references to "19" methods in JRuby by @headius in #576
- Make OpenStruct support as optional by @hsbt in #565
- Autoload JSON::GenericObject to avoid require ostruct warning in Ruby 3.4 by @tompng in #577
- Warn to install ostruct if json couldn't load it by @hsbt in #578
New Contributors
- @mperham made their first contribution in #571
- @peterzhu2118 made their first contribution in #574
Full Changelog: v2.7.1...v2.7.2
v2.7.1
What's Changed
Improved
- [DOC] RDoc for additions by @BurdetteLamar in #557
Fixed
- JSON.dump: handle unenclosed hashes regression by @casperisfine in #554
- Overload kwargs in JSON.dump by @k0kubun in #556
- Fix JSON.dump overload combination by @tompng in #558
Misc
New Contributors
Full Changelog: v2.7.0...v2.7.1