A summary of data about the Ruby ecosystem.

https://github.com/sferik/multi_json

A generic swappable back-end for JSON handling.
https://github.com/sferik/multi_json

Keywords from Contributors

activejob activerecord mvc rack rubygems rspec sinatra background-jobs multithreading sidekiq

Last synced: about 7 hours ago
JSON representation

Repository metadata

A generic swappable back-end for JSON handling.

README.md

MultiJSON

Tests
Linter
Mutant
Typecheck
Docs
Maintainability
Gem Version

Lots of Ruby libraries parse JSON and everyone has their favorite JSON coder.
Instead of choosing a single JSON coder and forcing users of your library to be
stuck with it, you can use MultiJSON instead, which will simply choose the
fastest available JSON coder. Here's how to use it:

require "multi_json"

MultiJSON.parse('{"abc":"def"}')                        #=> {"abc" => "def"}
MultiJSON.parse('{"abc":"def"}', symbolize_names: true) #=> {abc: "def"}
MultiJSON.generate({abc: "def"})                       # convert Ruby back to JSON
MultiJSON.generate({abc: "def"}, pretty: true)         # encoded in a pretty form (if supported by the coder)

[!IMPORTANT]
1.21.0 renames the public API to match Ruby stdlib JSON. The canonical
verbs are now MultiJSON.parse / MultiJSON.generate, and the canonical
module is MultiJSON (all-caps). The legacy MultiJson constant,
MultiJSON.load / MultiJSON.dump, :symbolize_keys, and friends still
work but emit one-time deprecation warnings and will be removed in 2.0.0.
Run your app with ruby -W:deprecated to surface them; the warnings are
tagged with the :deprecated category so you can silence the whole set with
Warning[:deprecated] = false. See Deprecated in 1.21.0
for the full list.

MultiJSON.parse returns nil for nil, empty, and whitespace-only inputs
instead of raising, so a missing or blank payload is observable as a nil
return value rather than an exception. When parsing invalid JSON, MultiJSON
will throw a MultiJSON::ParseError. MultiJSON::DecodeError and
MultiJSON::LoadError are aliases for backwards compatibility.

begin
  MultiJSON.parse("{invalid json}")
rescue MultiJSON::ParseError => exception
  exception.data    #=> "{invalid json}"
  exception.cause   #=> JSON::ParserError: ...
  exception.line    #=> 1 (for adapters that report a location, e.g. Oj or the json gem)
  exception.column  #=> 2
end

Drop-in replacement for stdlib JSON

MultiJSON mirrors the surface of Ruby's stdlib JSON so
most call sites swap in with a one-line change:

- require "json"
+ require "multi_json"

- JSON.parse(text, symbolize_names: true)
+ MultiJSON.parse(text, symbolize_names: true)

- JSON.generate(object, pretty: true)
+ MultiJSON.generate(object, pretty: true)

Method names and the common options line up with stdlib so existing
pretty-print calls and option keys keep working without changes:

stdlib JSON MultiJSON Status
JSON.parse(str) MultiJSON.parse(str)
JSON.generate(obj) MultiJSON.generate(obj)
pretty: true pretty: true
symbolize_names: true symbolize_names: true

Deprecated in 1.21.0

The module constant and primary verbs were renamed to match Ruby
stdlib JSON.parse / JSON.generate and the JSON spec (RFC 8259).
The old names still work in 1.x but now emit a one-time deprecation
warning; they will be removed in 2.0.0.

Deprecated Use instead
MultiJson (constant) MultiJSON (all-caps)
MultiJSON.load(str) MultiJSON.parse(str)
MultiJSON.dump(obj) MultiJSON.generate(obj)
MultiJSON.load_options= MultiJSON.parse_options=
MultiJSON.load_options MultiJSON.parse_options
MultiJSON.dump_options= MultiJSON.generate_options=
MultiJSON.dump_options MultiJSON.generate_options
symbolize_keys: option symbolize_names: option

The MultiJson constant (CamelCase) continues to work as a thin
delegator; every method call, constant lookup, and rescue clause
routes through MultiJSON transparently.

[!TIP]
The recommended upgrade path to 2.0 is: pin ~> 1.21 first, run
ruby -W:deprecated against your app or test suite to surface every
deprecation, migrate each call site to the canonical name, then bump to
~> 2.0. The 2.0 release deletes the deprecated aliases entirely, so the
warnings during 1.21.x are your map.

ParseError instance has cause reader which contains the original exception.
It also has data reader with the input that caused the problem, and line/column
readers populated for adapters whose error messages include a location (Oj and the
json gem). Adapters that don't include one (Yajl, fast_jsonparser) leave both nil.

Tuning the options cache

MultiJSON memoizes the merged option hash for each parse/generate call so
identical option hashes don't trigger repeated work. The cache is bounded —
defaulting to 1000 entries per direction — and applications that generate many
distinct option hashes can raise the ceiling at runtime:

MultiJSON::OptionsCache.max_cache_size = 5000

max_cache_size must be a positive integer; 0, negative values, and
non-integers raise ArgumentError.

Lowering the limit only takes effect for new inserts; existing cache
entries are left in place until normal eviction trims them below the
new ceiling. Call MultiJSON::OptionsCache.reset if you want to evict
immediately.

The use method, which sets the MultiJSON adapter, takes either a symbol or a
class (to allow for custom JSON parsers) that responds to both .load and .dump
at the class level.

When MultiJSON fails to load the specified adapter, it'll throw MultiJSON::AdapterError
which inherits from ArgumentError.

Writing a custom adapter

A custom adapter is any class that responds to two class methods plus
defines a ParseError constant:

class MyAdapter
  ParseError = Class.new(StandardError)

  def self.load(string, options)
    # parse string into a Ruby object, raising ParseError on failure
  end

  def self.dump(object, options)
    # serialize object to a JSON string
  end
end

MultiJSON.use(MyAdapter)

ParseError is required: MultiJSON.parse rescues MyAdapter::ParseError
to wrap parse failures in MultiJSON::ParseError, and an adapter that
omits the constant raises MultiJSON::AdapterError on the first parse
attempt instead of producing a confusing NameError.

For more, inherit from MultiJSON::Adapter to pick up shared option
merging, the defaults :load, ... / defaults :dump, ... DSL, and the
blank-input short-circuit. The built-in adapters in
lib/multi_json/adapters/ are working examples.

[!NOTE]
The adapter contract methods on the adapter class itself stay named
.load / .dump in 1.21.x (and the defaults :load, ... / defaults :dump, ... DSL keys match). The 2.0 release renames them to .parse /
.generate to align with the public API; if you ship a custom adapter,
you'll need to rename those methods (and the defaults keys) when you
upgrade.

MultiJSON tries to have intelligent defaulting. If any supported library is
already loaded, MultiJSON uses it before attempting to load others. When no
backend is preloaded, MultiJSON walks its preference list and uses the first
one that loads successfully. The list is split per platform — JRuby's
available adapter set differs from MRI's, and the bundled benchmark suite
ranks json_gem ahead of fast_jsonparser/oj/yajl on Ruby 3.4+. CI
re-runs the benchmark and fails if the observed ranking diverges from the
table below.

rank MRI / TruffleRuby JRuby
1 The JSON gem jrjackson
2 fast_jsonparser The JSON gem
3 oj gson
4 yajl-ruby

A dash means the adapter isn't usable on that runtime: fast_jsonparser,
oj, and yajl-ruby are MRI/TruffleRuby C extensions with no JRuby builds;
jrjackson and gson are JRuby-only. The JSON gem is a Ruby default gem,
so it's always available as a last-resort fallback on any supported Ruby.
If you have a workload where a different backend is faster, set it
explicitly with MultiJSON.use(:your_adapter).

Gem Variants

MultiJSON ships as two platform-specific gems. Bundler and RubyGems
automatically select the correct variant for your Ruby implementation:

ruby platform (MRI) java platform (JRuby)
Runtime dependency none concurrent-ruby ~> 1.2
fast_jsonparser adapter
oj adapter
yajl adapter
json_gem adapter
gson adapter
jr_jackson adapter
OptionsCache thread-safe store Hash + Mutex Concurrent::Map

Supported Ruby Versions

This library aims to support and is tested against the following Ruby
implementations:

  • Ruby 3.2
  • Ruby 3.3
  • Ruby 3.4
  • Ruby 4.0
  • JRuby 10.0 (targets Ruby 3.4 compatibility)
  • TruffleRuby 33.0 (native and JVM)

If something doesn't work in one of these implementations, it's a bug.

This library may inadvertently work (or seem to work) on other Ruby
implementations, however support will only be provided for the versions listed
above.

If you would like this library to support another Ruby version, you may
volunteer to be a maintainer. Being a maintainer entails making sure all tests
run and pass on that implementation. When something breaks on your
implementation, you will be responsible for providing patches in a timely
fashion. If critical issues for a particular implementation exist at the time
of a major release, support for that Ruby version may be dropped.

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations
of this scheme should be reported as bugs. Specifically, if a minor or patch
version is released that breaks backward compatibility, that version should be
immediately yanked and/or a new version should be immediately released that
restores compatibility. Breaking changes to the public API will only be
introduced with new major versions. As a result of this policy, you can (and
should) specify a dependency on this gem using the Pessimistic Version
Constraint
with two digits of precision. For example:

spec.add_dependency 'multi_json', '~> 1.0'

Copyright

Copyright (c) 2010-2026 Erik Berlin, Michael Bleigh, Josh Kalderimis, and Pavel
Pravosud. See LICENSE for details.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 950
Total Committers: 60
Avg Commits per committer: 15.833
Development Distribution Score (DDS): 0.401

Commits in past year: 315
Committers in past year: 4
Avg Commits per committer in past year: 78.75
Development Distribution Score (DDS) in past year: 0.051

Name Email Commits
Erik Berlin s****k@g****m 569
Pavel Pravosud p****l@p****m 213
Josh Kalderimis j****s@g****m 35
Michael Bleigh m****l@i****m 15
Jean Boussier j****r@g****m 11
Daniel Berger 7****6 10
Romain Tartière r****n@b****g 8
Guy Boertje g****e@g****m 5
Diego Elio 'Flameeyes' Pettenò f****s@g****m 5
Alex Koppel a****x@a****m 5
Gustav Munkby g****v@g****m 4
Joshua Peek j****h@j****m 4
Lukas Rieder l****r@g****m 4
Seth Vargo s****o@g****m 3
Takanori Ishikawa t****a@g****m 3
Trent Albright t****t@g****m 3
Ulysse Buonomo b****e@g****m 3
Ville Lautanala l****s@g****m 2
Sam Stephenson s****m@3****m 2
James A. Rosen j****s@z****m 2
Igor Kapkov i****k@m****m 2
Daniel Berger d****r@c****m 2
Bill Siggelkow b****w@m****m 2
Peter Marsh p****h@g****m 2
Aaron Patterson a****n@g****m 1
284km k****0@g****m 1
Andrew Pennebaker a****r@g****m 1
Daniel Farina d****a@m****m 1
Jorge Braz j****e@t****m 1
Rex Chung r****x@r****m 1
and 30 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 8 days ago

Total issues: 14
Total pull requests: 41
Average time to close issues: 4 days
Average time to close pull requests: about 12 hours
Total issue authors: 12
Total pull request authors: 5
Average comments per issue: 2.71
Average comments per pull request: 0.29
Merged pull request: 28
Bot issues: 0
Bot pull requests: 0

Past year issues: 14
Past year pull requests: 41
Past year average time to close issues: 4 days
Past year average time to close pull requests: about 12 hours
Past year issue authors: 12
Past year pull request authors: 5
Past year average comments per issue: 2.71
Past year average comments per pull request: 0.29
Past year merged pull request: 28
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/sferik/multi_json

Top Issue Authors

  • byroot (2)
  • sferik (2)
  • joceyall30-cell (1)
  • sandstrom (1)
  • gravitystorm (1)
  • soondl (1)
  • totus (1)
  • BaumiCoder (1)
  • mehmetc (1)
  • espen (1)
  • tjatkowski (1)
  • kruegerkyle95 (1)

Top Pull Request Authors

  • sferik (29)
  • byroot (8)
  • joceyall30-cell (2)
  • willnet (1)
  • smortex (1)

Top Issue Labels

Top Pull Request Labels

  • codex (29)

Package metadata

gem.coop: multi_json

A common interface to multiple JSON libraries, including fast_jsonparser, Oj, Yajl, and the JSON gem.

  • Homepage: https://github.com/sferik/multi_json
  • Documentation: http://www.rubydoc.info/gems/multi_json/
  • Licenses: MIT
  • Latest release: 1.21.1 (published about 1 month ago)
  • Last Synced: 2026-06-15T23:36:41.969Z (about 11 hours ago)
  • Versions: 73
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1,116,082,115 Total
  • Docker Downloads: 2,363,807,625
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Downloads: 0.012%
    • Average: 0.015%
    • Docker downloads count: 0.049%
  • Maintainers (4)
rubygems.org: multi_json

A common interface to multiple JSON libraries, including fast_jsonparser, Oj, Yajl, and the JSON gem.

  • Homepage: https://github.com/sferik/multi_json
  • Documentation: http://www.rubydoc.info/gems/multi_json/
  • Licenses: MIT
  • Latest release: 1.21.1 (published about 1 month ago)
  • Last Synced: 2026-06-14T13:43:22.216Z (2 days ago)
  • Versions: 73
  • Dependent Packages: 2,382
  • Dependent Repositories: 734,305
  • Downloads: 1,115,351,978 Total
  • Docker Downloads: 2,363,807,625
  • Rankings:
    • Downloads: 0.009%
    • Dependent repos count: 0.018%
    • Dependent packages count: 0.023%
    • Docker downloads count: 0.053%
    • Average: 0.765%
    • Stargazers count: 2.133%
    • Forks count: 2.352%
  • Maintainers (4)
pkgsrc-netbsd-x86_64-10.1-all: textproc/ruby-multi_json

General-purpose swappable JSON backend library

  • Homepage: https://github.com/sferik/multi_json
  • Documentation: https://pkgsrc.se/textproc/ruby-multi_json
  • Licenses: mit
  • Latest release: 1.19.1 (published 2 months ago)
  • Last Synced: 2026-05-27T10:25:15.229Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%

Dependencies

.github/workflows/docs.yml actions
  • actions/checkout v4 composite
  • ruby/setup-ruby v1 composite
.github/workflows/linter.yml actions
  • actions/checkout v4 composite
  • ruby/setup-ruby v1 composite
.github/workflows/tests.yml actions
  • actions/checkout v4 composite
  • ruby/setup-ruby v1 composite
.github/workflows/push.yml actions
  • actions/checkout v4 composite
  • ruby/setup-ruby v1 composite
  • rubygems/configure-rubygems-credentials v1.0.0 composite
.github/workflows/mutant.yml actions
  • actions/checkout v4 composite
  • ruby/setup-ruby v1 composite
Gemfile rubygems
  • gson >= 0.6
  • jrjackson >= 0.4.18
  • json ~> 2.0
  • json_pure ~> 2.0
  • rake >= 13.1
  • rspec >= 3.13
  • rubocop >= 1.62.1
  • rubocop-performance >= 1.20.2
  • rubocop-rake >= 0.6.0
  • rubocop-rspec >= 2.27.1
  • standard >= 1.35.1
multi_json.gemspec rubygems

Score: 29.935813713183187