Fork me on GitHub

peter@ohler.com
Ohler home

Oj (Optimized JSON) is fast. Faster than the built in Ruby json gem. Oj achieves this by implementing the encoding and decoding of JSON in C, as a C extension to Ruby.

The approach taken by both the json gem and ActiveSupport is to push JSON encoding to the individual object and then monkey patching those objects to implement encoding and decoding. Oj take a different approach and looks at Ruby objects as data and keeps the endcoding in C instead of going out to each object and encoding in Ruby. This is more of a service of function programming approach to encoding. Check out the benchmarks at https://github.com/stereobooster/ruby-json-benchmark. Enjoy Oj!

Star Watch Vote on Hacker News Documentation

3.0.0 Released

April 24, 2017


After more than a month Oj 3.0.0 is out. This is a major release focussed on json gem and Rails compatibility. Oj is now fully compatible mode with the json gem in ruby 2.4 and fully compatible with Rails 5.0. A new :custom mode was added as well.

Json gem: Oj is now a drop in replacement for the standard Ruby json gem. Just set Oj to mimic JSON and it passes all the json gem unit tests for Ruby 2.4. Older versions of Ruby will differ as the json gem changes from one release to another. Oj also offers some optimized versions of common classes such as Hash, Array, Time, BigDecimal and more.

Rails: Oj Rails mode passes all the ActiveSupport 5.0 encoding and decoding unit tests making it a drop in replacement. Options are included to use an optimized version of to_json and as_json methods on a class by class basis with further optimizations coming in the future.

Please give stereobooster a thank you for getting the tests set up and helping out with json gem and Rails understanding. He also has some benchmarks of Oj versus other options at https://github.com/stereobooster/ruby-json-benchmark.