# Oj

> A fast JSON parser and Object marshaller as a Ruby gem

Source: https://talira.ai/catalog/oj-bc21mcne
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [developer tools / parsing / json](https://talira.ai/categories/developer-tools/parsing/json), [languages / ruby](https://talira.ai/categories/languages/ruby)
- Licence: MIT[^2]
- Pricing: Free and open source[^2]
- Free tier: yes[^2]
- Self-hostable: yes[^3]
- API: yes[^3]
- Creator: Peter Ohler (ohler55), who also makes Ox and Agoo

Oj (Optimized JSON) is a JSON parser and serializer for Ruby written as a C extension. Its modes decide how documents map to Ruby: `:strict` and `:null` for plain JSON types, `:compat` to mimic the json gem, `:rails` to mimic ActiveSupport's encoder, `:object` to round-trip almost any Ruby object, and `:custom`. `Oj.optimize_rails` swaps Oj in for Rails' JSON encoding and the `JSON` methods, and `Oj::Parser` (3.13) is a faster parser with per-instance options. Peter Ohler has developed it since 2012; commercial support is sold through Tidelift.

## Links

- Website: https://www.ohler.com/oj/
- GitHub: https://github.com/ohler55/oj
- Docs: https://www.ohler.com/oj/doc/index.html

## Problems it solves

- JSON encoding is the slowest part of our Rails API responses
- parse large JSON payloads in Ruby faster than the standard json library
- make every to_json and JSON.parse call in my Rails app faster without touching the code
- serialize arbitrary Ruby objects to JSON and load them back as the same classes
- stream through a huge JSON file in Ruby without loading it all into memory
- parse untrusted JSON safely so it can't create Ruby objects of the attacker's choosing
- Rails-compatible JSON output, as_json and all, but quicker
- dump JSON with exact control over indentation, float precision and time formats
- store a serialized column as JSON with a faster coder than the default
- pull a few values out of a big JSON document without building the whole hash

## Features

- strict, null, compat (json gem), rails, object and custom modes
- Oj.optimize_rails to replace Rails' JSON encoder and decoder
- mimic_JSON to take over the JSON constant's methods
- Oj::Parser, a faster parser with option isolation
- Oj::Doc for fast access into a parsed document
- streaming and callback (SAJ, SCP) parsing
- safe_load and strict_load for untrusted input
- object mode that round-trips Ruby objects without monkey patching
- options for indentation, float precision, time formats and more
- usable as an ActiveRecord serialize coder

## Limitations

- Doesn't run on JRuby: it's a C extension, and JRuby support was removed[^1]

## Capabilities

- Has an API: plan not known

## Trust

Overall: 0.28 out of 1.
Signals: backing 0.20, extensibility 0.20.

- created by Peter Ohler (ohler55), who also makes Ox and Agoo

Warnings:

- GitHub activity not fetched yet

## Alternatives

- [json](https://talira.ai/catalog/json-r9196zbp.md): Ruby's JSON parser and generator, shipped with Ruby as a default gem

## Sources

[^1]: https://github.com/ohler55/oj/blob/develop/pages/Compatibility.md (checked 20 Nov 2026)
[^2]: https://github.com/ohler55/oj/blob/develop/LICENSE (checked 20 Nov 2026)
[^3]: https://github.com/ohler55/oj (checked 20 Nov 2026)
