oj_windows
A Windows-native, high-performance JSON parser and Object marshaller for Ruby.
Overview
oj_windows is a production-ready, Windows-exclusive fork optimized for the Ruby 3.4.8 MSVC environment. All POSIX-specific code has been removed or replaced with native Windows equivalents, ensuring maximum performance and stability on Windows systems.
Requirements
| Component | Version |
|---|---|
| Ruby | 3.4.8+ (MSVC build) |
| OS | Windows 10/11 x64 |
| Compiler | Visual Studio 2022+ |
| Architecture | x64-mswin64_140 |
Installation
gem install oj_windowsOr in your Gemfile:
gem 'oj_windows'Quick Start
require 'oj_windows'
# Dump Ruby objects to JSON
hash = { 'name' => 'oj_windows', 'version' => '3.16.14', 'windows' => true }
json = Oj.dump(hash)
# => {"name":"oj_windows","version":"3.16.14","windows":true}
# Load JSON back to Ruby objects
data = Oj.load(json)
# => {"name"=>"oj_windows", "version"=>"3.16.14", "windows"=>true}
# Pretty print
puts Oj.dump(hash, indent: 2)Features
- High Performance: Optimized C extension compiled with MSVC
- Multiple Modes: Strict, Compat, Object, Custom, Rails, WAB, Null
-
JSON Gem Compatibility: Drop-in replacement via
Oj.mimic_JSON - Rails Integration: Full ActiveSupport/ActiveRecord support
- Streaming: SAJ and SC parsers for large documents
- StringWriter/StreamWriter: Efficient JSON generation
Test Results
All tests pass on Windows MSVC Ruby 3.4.8:
| Test Suite | Runs | Assertions | Failures | Errors | Skips |
|---|---|---|---|---|---|
| test_various.rb | 69 | 8,202 | 0 | 0 | 1 |
| test_strict.rb | 42 | 71 | 0 | 0 | 0 |
| test_compat.rb | 55 | 112 | 0 | 0 | 0 |
| test_object.rb | 74 | 160 | 0 | 0 | 0 |
| test_fast.rb | 43 | 137 | 0 | 0 | 0 |
| test_saj.rb | 13 | 18 | 0 | 0 | 0 |
| test_scp.rb | 23 | 23 | 0 | 0 | 2 |
| test_gc.rb | 3 | 50 | 0 | 0 | 0 |
| test_writer.rb | 27 | 28 | 0 | 0 | 1 |
| test_file.rb | 21 | 52 | 0 | 0 | 1 |
| test_hash.rb | 3 | 7 | 0 | 0 | 0 |
| Total | 373 | 8,860 | 0 | 0 | 6 |
Note: The 6 skipped tests are fork-based operations that are not supported on Windows. This is expected behavior.
Performance Benchmarks
Benchmarks run on Windows with Ruby 3.4.8 MSVC (50,000 iterations):
Parse Performance
| Parser | Ops/sec |
|---|---|
| JSON::Ext | 444,501 |
| Oj:wab | 402,185 |
| Oj:strict | 380,664 |
Dump Performance
| Dumper | Ops/sec |
|---|---|
| JSON::Ext | 832,994 |
| Oj:strict | 816,299 |
* In synthetic benchmarks with simple data structures, Ruby's native
JSON::Extmay appear faster because it is tightly integrated with the Ruby VM. However,oj_windowsprovides significant advantages:
- Object mode: Full Ruby object serialization/deserialization (not possible with JSON gem)
- Rails/ActiveSupport: Optimized
as_json/to_jsonintegration- Streaming parsers: SAJ and SCP for memory-efficient parsing of large documents
- Circular references: Automatic detection and handling
- Custom behaviors: Fine-grained control over serialization
For complex real-world applications with deep object graphs, custom types, and Rails integration,
oj_windowsremains the optimal choice.
Modes
| Mode | Description |
|---|---|
:strict |
Strict JSON compliance, only native types |
:compat |
Compatible with the JSON gem |
:object |
Full Ruby object serialization |
:custom |
Customizable serialization behavior |
:rails |
Rails and ActiveSupport compatibility |
:wab |
WAB (Web Application Builder) format |
:null |
Return null for unsupported types |
Configuration
# Set default options
Oj.default_options = {
mode: :compat,
symbol_keys: true,
indent: 2
}
# Check current options
Oj.default_optionsDocumentation
- Options - Parse and dump options
- Modes - Detailed mode documentation
- Rails - Rails integration guide
- JsonGem - JSON gem compatibility
- Advanced - Advanced features
Building from Source
# Requires MSVC environment
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
# Build and install
.\package_install.batRunning Tests
cd test
.\test_all_no_rails.batLicense
MIT License - See LICENSE for details.
Version 3.16.14 - December 2025 Original OJ https://github.com/ohler55/oj