How ohler55/oj works
Oj is a Ruby gem providing fast JSON parsing and Ruby-object marshalling. The main workflow accepts Ruby values or JSON input through the extension, applies mode-specific parsing or serialization, and returns Ruby objects or JSON output. It also offers an event-driven callback parser, a newer configurable parser, and compatibility behavior for the JSON gem and Rails/ActiveSupport. The graph follows documented modes and sampled dispatch code; some subsystem links use directory-level paths because their wiring was not shown in the excerpts.
Main entry points: oj.c Mode dispatch · json.rb JSON shim · oj.rb Oj Ruby API · parse.c Legacy parsers
Components 22
Ruby interfaces
- Oj Ruby API
lib/oj.rb - Native extension
ext/oj/oj.c - Mode dispatch
ext/oj/oj.c - Ruby result
Parsing
- Legacy parsers
ext/oj/parse.c - Strict parser
ext/oj/strict.c - Compat parser
ext/oj/compat.c - Custom parser
ext/oj/custom.c - Object parser
ext/oj/object.c - WAB parser
ext/oj/wab.c - Fast parser
ext/oj/parser.c - Callback parsing
ext/oj/scp.c - SAJ parsing
ext/oj/saj.c
Marshalling
- Dump dispatch
ext/oj/oj.c - Dump engine
ext/oj/dump.c - Mode serializers
ext/oj - Stream output
ext/oj/stream_writer.c
Compatibility
- JSON shim
lib/oj/json.rb - Rails support
ext/oj/rails.c - Mimic behavior
lib/oj/mimic.rb - Generator state
lib/oj/state.rb
Other components
- Ruby caller
Connections 25
- Ruby caller → Oj Ruby API: calls
- Oj Ruby API → Native extension: loads
- Native extension → Mode dispatch: dispatches
- Mode dispatch → Legacy parsers: parses legacy
- Mode dispatch → Strict parser: selects strict
- Mode dispatch → Compat parser: selects compat
- Mode dispatch → Custom parser: selects custom
- Mode dispatch → Object parser: selects object
- Mode dispatch → WAB parser: selects WAB
- Ruby caller → Fast parser: uses parser
- Ruby caller → Callback parsing: requests callbacks
- Ruby caller → SAJ parsing: requests SAJ
- Legacy parsers → Ruby result: returns
- Fast parser → Ruby result: returns
- Callback parsing → Ruby result: emits values
- SAJ parsing → Ruby result: emits events
- Ruby caller → Dump dispatch: dumps value
- Dump dispatch → Dump engine: serializes
- Dump dispatch → Mode serializers: selects mode
- Dump engine → Stream output: writes output
- Dump dispatch → Rails support: uses Rails mode
- Ruby caller → JSON shim: uses JSON API
- JSON shim → Generator state: configures state
- JSON shim → Mimic behavior: applies mimic
- Mimic behavior → Ruby caller: provides compatibility