oj_windows 3.16.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +44 -0
  3. data/LICENSE +21 -0
  4. data/README.md +164 -0
  5. data/ext/oj_windows/buf.h +85 -0
  6. data/ext/oj_windows/cache.c +339 -0
  7. data/ext/oj_windows/cache.h +22 -0
  8. data/ext/oj_windows/cache8.c +105 -0
  9. data/ext/oj_windows/cache8.h +21 -0
  10. data/ext/oj_windows/circarray.c +64 -0
  11. data/ext/oj_windows/circarray.h +22 -0
  12. data/ext/oj_windows/code.c +214 -0
  13. data/ext/oj_windows/code.h +40 -0
  14. data/ext/oj_windows/compat.c +239 -0
  15. data/ext/oj_windows/custom.c +1074 -0
  16. data/ext/oj_windows/debug.c +126 -0
  17. data/ext/oj_windows/dump.c +1556 -0
  18. data/ext/oj_windows/dump.h +110 -0
  19. data/ext/oj_windows/dump_compat.c +901 -0
  20. data/ext/oj_windows/dump_leaf.c +162 -0
  21. data/ext/oj_windows/dump_object.c +710 -0
  22. data/ext/oj_windows/dump_strict.c +405 -0
  23. data/ext/oj_windows/encode.h +16 -0
  24. data/ext/oj_windows/err.c +57 -0
  25. data/ext/oj_windows/err.h +67 -0
  26. data/ext/oj_windows/extconf.rb +77 -0
  27. data/ext/oj_windows/fast.c +1710 -0
  28. data/ext/oj_windows/intern.c +325 -0
  29. data/ext/oj_windows/intern.h +22 -0
  30. data/ext/oj_windows/mem.c +320 -0
  31. data/ext/oj_windows/mem.h +53 -0
  32. data/ext/oj_windows/mimic_json.c +919 -0
  33. data/ext/oj_windows/object.c +726 -0
  34. data/ext/oj_windows/odd.c +245 -0
  35. data/ext/oj_windows/odd.h +43 -0
  36. data/ext/oj_windows/oj.c +2097 -0
  37. data/ext/oj_windows/oj.h +420 -0
  38. data/ext/oj_windows/parse.c +1317 -0
  39. data/ext/oj_windows/parse.h +113 -0
  40. data/ext/oj_windows/parser.c +1600 -0
  41. data/ext/oj_windows/parser.h +103 -0
  42. data/ext/oj_windows/rails.c +1484 -0
  43. data/ext/oj_windows/rails.h +18 -0
  44. data/ext/oj_windows/reader.c +222 -0
  45. data/ext/oj_windows/reader.h +137 -0
  46. data/ext/oj_windows/resolve.c +80 -0
  47. data/ext/oj_windows/resolve.h +12 -0
  48. data/ext/oj_windows/rxclass.c +144 -0
  49. data/ext/oj_windows/rxclass.h +26 -0
  50. data/ext/oj_windows/saj.c +675 -0
  51. data/ext/oj_windows/saj2.c +584 -0
  52. data/ext/oj_windows/saj2.h +23 -0
  53. data/ext/oj_windows/scp.c +187 -0
  54. data/ext/oj_windows/simd.h +47 -0
  55. data/ext/oj_windows/sparse.c +946 -0
  56. data/ext/oj_windows/stream_writer.c +329 -0
  57. data/ext/oj_windows/strict.c +189 -0
  58. data/ext/oj_windows/string_writer.c +517 -0
  59. data/ext/oj_windows/trace.c +72 -0
  60. data/ext/oj_windows/trace.h +55 -0
  61. data/ext/oj_windows/usual.c +1218 -0
  62. data/ext/oj_windows/usual.h +69 -0
  63. data/ext/oj_windows/util.c +136 -0
  64. data/ext/oj_windows/util.h +20 -0
  65. data/ext/oj_windows/val_stack.c +101 -0
  66. data/ext/oj_windows/val_stack.h +151 -0
  67. data/ext/oj_windows/validate.c +46 -0
  68. data/ext/oj_windows/wab.c +584 -0
  69. data/lib/oj/active_support_helper.rb +39 -0
  70. data/lib/oj/bag.rb +95 -0
  71. data/lib/oj/easy_hash.rb +52 -0
  72. data/lib/oj/error.rb +21 -0
  73. data/lib/oj/json.rb +188 -0
  74. data/lib/oj/mimic.rb +301 -0
  75. data/lib/oj/saj.rb +80 -0
  76. data/lib/oj/schandler.rb +143 -0
  77. data/lib/oj/state.rb +135 -0
  78. data/lib/oj/version.rb +4 -0
  79. data/lib/oj_windows/active_support_helper.rb +39 -0
  80. data/lib/oj_windows/bag.rb +95 -0
  81. data/lib/oj_windows/easy_hash.rb +52 -0
  82. data/lib/oj_windows/error.rb +21 -0
  83. data/lib/oj_windows/json.rb +188 -0
  84. data/lib/oj_windows/mimic.rb +301 -0
  85. data/lib/oj_windows/saj.rb +80 -0
  86. data/lib/oj_windows/schandler.rb +143 -0
  87. data/lib/oj_windows/state.rb +135 -0
  88. data/lib/oj_windows/version.rb +4 -0
  89. data/lib/oj_windows.rb +15 -0
  90. data/pages/Advanced.md +38 -0
  91. data/pages/Compatibility.md +49 -0
  92. data/pages/Custom.md +37 -0
  93. data/pages/Encoding.md +61 -0
  94. data/pages/InstallOptions.md +20 -0
  95. data/pages/JsonGem.md +60 -0
  96. data/pages/Modes.md +94 -0
  97. data/pages/Options.md +339 -0
  98. data/pages/Parser.md +134 -0
  99. data/pages/Rails.md +85 -0
  100. data/pages/Security.md +43 -0
  101. data/pages/WAB.md +12 -0
  102. metadata +242 -0
data/pages/Advanced.md ADDED
@@ -0,0 +1,38 @@
1
+ # Advanced Features
2
+
3
+ `oj_windows` is a high-performance JSON parser and serializer for Windows MSVC Ruby.
4
+ It provides multiple serialization modes and alternative parsing APIs for different use cases.
5
+
6
+ ## Serialization Modes
7
+
8
+ `oj_windows` has several `dump` modes which control how Ruby Objects are
9
+ converted to JSON. These modes are set with the `:mode` option in either the
10
+ default options or as one of the options to the `dump` method:
11
+
12
+ - `:strict` - Strict JSON compliance
13
+ - `:compat` - JSON gem compatibility
14
+ - `:object` - Full Ruby object serialization
15
+ - `:custom` - Customizable behavior
16
+ - `:rails` - Rails/ActiveSupport integration
17
+ - `:wab` - WAB format
18
+
19
+ ## Alternative Parser APIs
20
+
21
+ ### Oj::Doc API
22
+
23
+ The fastest alternative parser API is the `Oj::Doc` API. It takes
24
+ a completely different approach by opening a JSON document and providing calls
25
+ to navigate around the JSON while it is open. This approach provides
26
+ efficient access for large documents where only specific elements are needed.
27
+
28
+ ### Callback Parsers (SAJ/SCP)
29
+
30
+ The `Oj::Saj` and `Oj::ScHandler` APIs are callback parsers that
31
+ walk the JSON document depth first and make callbacks for each element.
32
+ Both callback parsers are useful when only portions of the JSON are of
33
+ interest, providing memory-efficient parsing of large documents.
34
+
35
+ ### Oj::Parser API
36
+
37
+ The `Oj::Parser` API provides the best balance of performance and flexibility.
38
+ See [Parser.md](Parser.md) for detailed benchmarks on Windows MSVC Ruby 3.4.8.
@@ -0,0 +1,49 @@
1
+ # Compatibility
2
+
3
+ `oj_windows` is a **Windows-exclusive** fork optimized for the MSVC toolchain.
4
+
5
+ ## Platform Support
6
+
7
+ | Platform | Status |
8
+ |----------|--------|
9
+ | Windows (MSVC) | ✅ Fully supported |
10
+ | Windows (MinGW) | ❌ Not supported |
11
+ | Linux | ❌ Not supported |
12
+ | macOS | ❌ Not supported |
13
+
14
+ ## Ruby Version
15
+
16
+ | Version | Status |
17
+ |---------|--------|
18
+ | Ruby 3.4.8+ (MSVC) | ✅ Fully supported |
19
+ | Older Ruby versions | ❌ Not supported |
20
+
21
+ ## Requirements
22
+
23
+ - **Ruby**: 3.4.8+ compiled with MSVC
24
+ - **OS**: Windows 10/11 x64
25
+ - **Compiler**: Visual Studio 2022+
26
+ - **Architecture**: x64-mswin64_140
27
+
28
+ ## Rails Compatibility
29
+
30
+ `oj_windows` is compatible with:
31
+
32
+ | Rails Version | Status |
33
+ |---------------|--------|
34
+ | Rails 7.x | ✅ Supported |
35
+ | Rails 8.x | ✅ Supported |
36
+
37
+ Note: Rails projects may use [multi_json](https://github.com/intridea/multi_json) which will automatically prefer oj_windows if installed.
38
+
39
+ ## JSON Gem Compatibility
40
+
41
+ `oj_windows` can serve as a drop-in replacement for the Ruby JSON gem:
42
+
43
+ ```ruby
44
+ require 'oj_windows'
45
+
46
+ Oj.mimic_JSON()
47
+ ```
48
+
49
+ See [JsonGem.md](JsonGem.md) for full compatibility details.
data/pages/Custom.md ADDED
@@ -0,0 +1,37 @@
1
+ # Custom Mode
2
+
3
+ The `:custom` mode is the most configurable mode in `oj_windows` and honors almost all
4
+ options. It provides maximum flexibility for JSON serialization and parsing.
5
+
6
+ ## Overview
7
+
8
+ The `:custom` mode can be configured by:
9
+ - Passing options to `Oj.dump()` and `Oj.load()` methods
10
+ - Modifying the default options via `Oj.default_options`
11
+
12
+ ## Object Creation
13
+
14
+ The ability to create Ruby objects from JSON object elements is supported via
15
+ the `:create_additions` option.
16
+
17
+ Special treatment is given to the `:create_id` option:
18
+
19
+ | `:create_id` Value | Behavior |
20
+ |--------------------|----------|
21
+ | `"^o"` | Uses efficient internal encoding/decoding (recommended) |
22
+ | Other values | Calls `to_json` and `create_json` methods (JSON gem compatible) |
23
+
24
+ When using `"^o"`, the internal encoding is more efficient and does not require
25
+ the target classes to implement `to_json` or `create_json` methods.
26
+
27
+ ## Configuration Example
28
+
29
+ ```ruby
30
+ require 'oj_windows'
31
+
32
+ Oj.default_options = {
33
+ mode: :custom,
34
+ create_additions: true,
35
+ create_id: '^o'
36
+ }
37
+ ```
data/pages/Encoding.md ADDED
@@ -0,0 +1,61 @@
1
+ # Object Mode Encoding
2
+
3
+ Object mode in `oj_windows` provides fast Ruby object serialization and deserialization.
4
+ In `:object` mode, JSON is generated following conventions that allow Class information
5
+ and Object IDs for circular reference detection to be encoded in the JSON document.
6
+
7
+ ## Encoding Rules
8
+
9
+ ### Native Types
10
+ JSON native types (`true`, `false`, `nil`, `String`, `Hash`, `Array`, `Number`) are
11
+ encoded normally.
12
+
13
+ ### Symbols
14
+ A Symbol is encoded as a JSON string with a preceding `':'` character.
15
+
16
+ ### Special Key Markers
17
+ The `'^'` character denotes a special key value in a JSON Object sequence.
18
+
19
+ | Key | Description |
20
+ |-----|-------------|
21
+ | `"^c"` | Ruby class. Example: `{"^c":"MyModule::MyClass"}` |
22
+ | `"^t"` | Ruby Time. Example: `{"^t":1325775487.000000}` |
23
+ | `"^o"` | Ruby Object with instance variables |
24
+ | `"^O"` | Built-in/odd classes (Rational, Date, DateTime) |
25
+ | `"^u"` | Ruby Struct. Example: `{"^u":["Range",1,7,false]}` |
26
+ | `"^i"` | Object ID for circular reference detection |
27
+ | `"^r"` | Reference to previously encoded Object |
28
+
29
+ ### Object Encoding Example
30
+
31
+ ```json
32
+ {"^o":"MyClass","x":58,"y":"value"}
33
+ ```
34
+
35
+ This represents an instance of `MyClass` with `@x = 58` and `@y = "value"`.
36
+
37
+ ### Circular References
38
+
39
+ When `:circular` option is enabled:
40
+
41
+ ```json
42
+ {"^o":"MyClass","^i":1,"x":3,"me":"^r1"}
43
+ ```
44
+
45
+ The `"^i":1` assigns ID 1 to this object, and `"^r1"` references it.
46
+
47
+ ### Hash with Non-String Keys
48
+
49
+ Hash entries with non-String/Symbol keys are encoded as:
50
+
51
+ ```json
52
+ {"^#3":[2,5]}
53
+ ```
54
+
55
+ Where the value is `[key, value]` and `^#3` is a hex identifier.
56
+
57
+ ### String Escaping
58
+
59
+ Ruby Strings starting with `':'` or `'^'` are escaped:
60
+ - `':'` becomes `'\u003a'`
61
+ - `'^'` becomes `'\u005e'`
@@ -0,0 +1,20 @@
1
+ # Oj Windows Install Options
2
+
3
+ ### Enable trace log
4
+
5
+ ```powershell
6
+ gem install oj_windows -- --enable-trace-log
7
+ ```
8
+
9
+ To enable Oj trace feature on Windows, use the `--enable-trace-log` option when installing the gem.
10
+ Then, the trace logs will be displayed when `:trace` option is set to `true`.
11
+
12
+
13
+ ### Enable SIMD instructions
14
+
15
+ ```powershell
16
+ gem install oj_windows -- --with-sse42
17
+ ```
18
+
19
+ To enable the use of SIMD instructions in Oj, use the `--with-sse42` option when installing the gem.
20
+ This will enable the use of the SSE4.2 instructions in the internal parser for improved performance.
data/pages/JsonGem.md ADDED
@@ -0,0 +1,60 @@
1
+ # JSON Gem Compatibility
2
+
3
+ `oj_windows` can serve as a drop-in replacement for the Ruby JSON gem with improved performance on Windows MSVC.
4
+
5
+ ## Quick Start
6
+
7
+ To have `oj_windows` take over the `JSON` constant methods (`load`, `parse`, etc.):
8
+
9
+ ```ruby
10
+ require 'oj_windows'
11
+
12
+ Oj.mimic_JSON()
13
+ ```
14
+
15
+ If your project already requires the `json` gem, call `Oj.mimic_JSON()` after the json gem has been loaded.
16
+
17
+ ## Optimized Type Encoding
18
+
19
+ For faster encoding of common types, add them to Oj's optimized list:
20
+
21
+ ```ruby
22
+ Oj.add_to_json(Array, BigDecimal, Complex, Date, DateTime, Exception, Hash, Integer, OpenStruct, Range, Rational, Regexp, Struct, Time)
23
+
24
+ # Or add all available types:
25
+ # Oj.add_to_json()
26
+ ```
27
+
28
+ To revert a type to unoptimized encoding:
29
+
30
+ ```ruby
31
+ Oj.remove_to_json(Rational)
32
+ ```
33
+
34
+ ## Supported Types
35
+
36
+ The following types can be added for optimized encoding:
37
+
38
+ | Type | Description |
39
+ |------|-------------|
40
+ | Array | Ruby arrays |
41
+ | BigDecimal | Arbitrary precision decimals |
42
+ | Complex | Complex numbers |
43
+ | Date | Date objects |
44
+ | DateTime | Date with time |
45
+ | Exception | Exception objects |
46
+ | Hash | Ruby hashes |
47
+ | Integer | Integer values |
48
+ | OpenStruct | OpenStruct objects |
49
+ | Range | Range objects |
50
+ | Rational | Rational numbers |
51
+ | Regexp | Regular expressions |
52
+ | Struct | Struct objects |
53
+ | Time | Time objects |
54
+
55
+ ## Compatibility Notes
56
+
57
+ - `oj_windows` in `:compat` mode mimics the json gem's `to_json(*)` method behavior
58
+ - JSON.generate(), JSON.dump(), and JSON() functions are supported
59
+ - NaN and Infinity handling matches the json gem's behavior
60
+ - Compatibility target is json gem version 2.0.3
data/pages/Modes.md ADDED
@@ -0,0 +1,94 @@
1
+ # Modes
2
+
3
+ `oj_windows` provides multiple modes to control JSON serialization and parsing behavior.
4
+
5
+ ## Available Modes
6
+
7
+ | Mode | Description |
8
+ |------|-------------|
9
+ | `:strict` | Strict JSON compliance, native types only |
10
+ | `:null` | Like strict, but outputs null for unsupported types |
11
+ | `:compat` / `:json` | JSON gem compatible |
12
+ | `:rails` | ActiveSupport/Rails compatible |
13
+ | `:object` | Full Ruby object serialization |
14
+ | `:custom` | Maximum flexibility, honors all options |
15
+ | `:wab` | WAB format for web applications |
16
+
17
+ ## Mode Details
18
+
19
+ ### :strict Mode
20
+
21
+ Strict mode follows JSON specifications exactly. Only native JSON types are supported:
22
+ - Boolean (`true`, `false`)
23
+ - `nil`
24
+ - String
25
+ - Hash
26
+ - Array
27
+ - Numbers
28
+
29
+ Non-native types raise an Exception. This is the safest mode for parsing untrusted input.
30
+
31
+ ### :null Mode
32
+
33
+ Similar to `:strict`, but outputs JSON `null` for non-native types instead of raising an Exception.
34
+
35
+ ### :compat Mode
36
+
37
+ Mimics the Ruby JSON gem. Uses `to_json(*)` methods for serialization.
38
+ See [JsonGem.md](JsonGem.md) for details.
39
+
40
+ ```ruby
41
+ Oj.mimic_JSON() # Take over JSON module methods
42
+ ```
43
+
44
+ ### :rails Mode
45
+
46
+ Mimics ActiveSupport's encoder. Uses `as_json(*)` methods for serialization.
47
+ See [Rails.md](Rails.md) for details.
48
+
49
+ ```ruby
50
+ Oj.optimize_rails() # Full Rails integration
51
+ ```
52
+
53
+ ### :object Mode
54
+
55
+ Full Ruby object serialization and deserialization. Encodes class information,
56
+ circular references, and object IDs in the JSON output.
57
+ See [Encoding.md](Encoding.md) for the encoding format.
58
+
59
+ ### :custom Mode
60
+
61
+ Maximum flexibility with all options honored. Cannot exactly replicate other modes
62
+ but provides the most control. See [Custom.md](Custom.md) for details.
63
+
64
+ ### :wab Mode
65
+
66
+ Optimized for WAB (Web Application Builder) data exchange. Only honors the indent option.
67
+ See [WAB.md](WAB.md) for details.
68
+
69
+ ## Setting the Mode
70
+
71
+ ```ruby
72
+ require 'oj_windows'
73
+
74
+ # Set default mode
75
+ Oj.default_options = { mode: :compat }
76
+
77
+ # Or per-call
78
+ json = Oj.dump(data, mode: :strict)
79
+ data = Oj.load(json, mode: :strict)
80
+ ```
81
+
82
+ ## Mode Consistency
83
+
84
+ Use the same mode for both dumping and loading. Mixing modes may produce unexpected results.
85
+
86
+ ```ruby
87
+ # Correct: same mode for dump and load
88
+ json = Oj.dump(obj, mode: :object)
89
+ obj2 = Oj.load(json, mode: :object)
90
+
91
+ # Incorrect: mixed modes
92
+ json = Oj.dump(obj, mode: :object)
93
+ obj2 = Oj.load(json, mode: :strict) # May fail or lose data
94
+ ```
data/pages/Options.md ADDED
@@ -0,0 +1,339 @@
1
+ # Options
2
+
3
+ `oj_windows` provides extensive configuration options for JSON serialization and parsing.
4
+
5
+ ## Setting Default Options
6
+
7
+ ```ruby
8
+ require 'oj_windows'
9
+
10
+ Oj.default_options = { mode: :compat }
11
+ ```
12
+
13
+ Another way to make use of options when calling load or dump methods is to
14
+ pass in a Hash with the options already set in the Hash. This is slightly less
15
+ efficient than setting the globals for many smaller JSON documents but does
16
+ provide a more thread safe approach to using custom options for loading and
17
+ dumping.
18
+
19
+ ### Options for serializer and parser
20
+
21
+ ### :allow_blank [Boolean]
22
+
23
+ If true a nil input to load will return nil and not raise an Exception.
24
+
25
+ ### :allow_gc [Boolean]
26
+
27
+ Allow or prohibit GC during parsing, default is true (allow).
28
+
29
+ ### :allow_invalid_unicode [Boolean]
30
+
31
+ Allow invalid unicode, default is false (don't allow).
32
+
33
+ ### :allow_nan
34
+
35
+ Alias for the :nan option.
36
+
37
+ ### :array_class [Class]
38
+
39
+ Class to use instead of Array on load.
40
+
41
+ ### :array_nl
42
+
43
+ Trailer appended to the end of an array dump. The default is an empty
44
+ string. Primarily intended for json gem compatibility. Using just indent as an
45
+ integer gives better performance.
46
+
47
+ ### :ascii_only
48
+
49
+ If true all non-ASCII character are escaped when dumping. This is the same as
50
+ setting the :escape_mode options to :ascii and exists for json gem
51
+ compatibility.
52
+
53
+ ### :auto_define [Boolean]
54
+
55
+ Automatically define classes if they do not exist.
56
+
57
+ ### :bigdecimal_as_decimal [Boolean]
58
+
59
+ If true dump BigDecimal as a decimal number otherwise as a String
60
+
61
+ ### :bigdecimal_load [Symbol]
62
+
63
+ Determines how to load decimals.
64
+
65
+ - `:bigdecimal` convert all decimal numbers to BigDecimal.
66
+
67
+ - `:float` convert all decimal numbers to Float.
68
+
69
+ - `:auto` the most precise for the number of digits is used.
70
+
71
+ - `:fast` faster conversion to Float.
72
+
73
+ - `:ruby` convert to Float using the Ruby `to_f` conversion.
74
+
75
+ This can also be set with `:decimal_class` when used as a load or
76
+ parse option to match the JSON gem. In that case either `Float`,
77
+ `BigDecimal`, or `nil` can be provided.
78
+
79
+ ### :cache_keys [Boolean]
80
+
81
+ If true Hash keys are cached or interned. There are trade-offs with
82
+ caching keys. Large caches will use more memory and in extreme cases
83
+ (like over a million) the cache may be slower than not using
84
+ it. Repeated parsing of similar JSON docs is where cache_keys shines
85
+ especially with symbol keys.
86
+
87
+ There is a maximum length for cached keys. Any key longer than 34
88
+ bytes is not cached. Everything still works but the key is not cached.
89
+
90
+ ### :cache_strings [Int]
91
+
92
+ Shorter strings can be cached for better performance. A limit,
93
+ cache_strings, defines the upper limit on what strings are cached. As
94
+ with cached keys only strings less than 35 bytes are cached even if
95
+ the limit is set higher. Setting the limit to zero effectively
96
+ disables the caching of string values.
97
+
98
+ Note that caching for strings is for string values and not Hash keys
99
+ or Object attributes.
100
+
101
+ ### :circular [Boolean]
102
+
103
+ Detect circular references while dumping. In :compat mode raise a
104
+ NestingError. For other modes except the :object mode place a null in the
105
+ output. For :object mode place references in the output that will be used to
106
+ recreate the looped references on load.
107
+
108
+ ### :class_cache [Boolean]
109
+
110
+ Cache classes for faster parsing. This option should not be used if
111
+ dynamically modifying classes or reloading classes then don't use this.
112
+
113
+ ### :compat_bigdecimal [Boolean]
114
+
115
+ Determines how to load decimals when in `:compat` mode.
116
+
117
+ - `true` convert all decimal numbers to BigDecimal.
118
+
119
+ - `false` convert all decimal numbers to Float.
120
+
121
+ ### :create_additions
122
+
123
+ A flag indicating that the :create_id key, when encountered during parsing,
124
+ should create an Object matching the class name specified in the value
125
+ associated with the key.
126
+
127
+ ### :create_id [String]
128
+
129
+ The :create_id option specifies that key is used for dumping and loading when
130
+ specifying the class for an encoded object. The default is `json_create`.
131
+
132
+ In the `:custom` mode, setting the `:create_id` to nil will cause Complex,
133
+ Rational, Range, and Regexp to be output as strings instead of as JSON
134
+ objects.
135
+
136
+ ### :empty_string [Boolean]
137
+
138
+ If true an empty or all whitespace input will not raise an Exception. The
139
+ default_options will be honored for :null, :strict, and :custom modes. Ignored
140
+ for :custom and :wab. The :compat has a more complex set of rules. The JSON
141
+ gem compatibility is best described by examples.
142
+
143
+ ```
144
+ JSON.parse('') => raise
145
+ JSON.parse(' ') => raise
146
+ JSON.load('') => nil
147
+ JSON.load('', nil, allow_blank: false) => raise
148
+ JSON.load('', nil, allow_blank: true) => nil
149
+ JSON.load(' ') => raise
150
+ JSON.load(' ', nil, allow_blank: false) => raise
151
+ JSON.load(' ', nil, allow_blank: true) => raise
152
+ ```
153
+
154
+ ### :escape_mode [Symbol]
155
+
156
+ Determines the characters to escape when dumping. Only the :ascii and
157
+ :json modes are supported in :compat mode.
158
+
159
+ - `:newline` allows unescaped newlines in the output.
160
+
161
+ - `:json` follows the JSON specification. This is the default mode.
162
+
163
+ - `:slash` escapes `/` characters.
164
+
165
+ - `:xss_safe` escapes HTML and XML characters such as `&` and `<`.
166
+
167
+ - `:ascii` escapes all non-ascii or characters with the hi-bit set.
168
+
169
+ - `:unicode_xss` escapes a special unicodes and is xss safe.
170
+
171
+ ### :float_precision [Fixnum]
172
+
173
+ The number of digits of precision when dumping floats, 0 indicates use Ruby directly.
174
+
175
+ ### :hash_class [Class]
176
+
177
+ Class to use instead of Hash on load. This is the same as the :object_class.
178
+
179
+ ### :ignore [Array]
180
+
181
+ Ignore all the classes in the Array when dumping. A value of nil indicates
182
+ ignore nothing.
183
+
184
+ ### :indent [Fixnum]
185
+
186
+ Number of spaces to indent each element in a JSON document, zero is no newline
187
+ between JSON elements, negative indicates no newline between top level JSON
188
+ elements in a stream.
189
+
190
+ ### :indent_str
191
+
192
+ Indentation for each element when dumping. The default is an empty
193
+ string. Primarily intended for json gem compatibility. Using just indent as an
194
+ integer gives better performance.
195
+
196
+ ### :integer_range [Range]
197
+
198
+ Dump integers outside range as strings.
199
+ Note: range bounds must be Fixnum.
200
+
201
+ ### :match_string
202
+
203
+ Provides a means to detect strings that should be used to create non-String
204
+ objects. The value to the option must be a Hash with keys that are regular
205
+ expressions and values are class names. For strict json gem compatibility a
206
+ RegExp should be used. For better performance but sacrificing some regexp
207
+ options a string can be used and the C version of regex will be used instead.
208
+
209
+ ### :max_nesting
210
+
211
+ The maximum nesting depth on both dump and load that is allowed. This exists
212
+ for json gem compatibility.
213
+
214
+ ### :mode [Symbol]
215
+
216
+ Primary behavior for loading and dumping. The :mode option controls which
217
+ other options are in effect. For more details see the {file:Modes.md} page. By
218
+ default Oj uses the :custom mode which is provides the highest degree of
219
+ customization.
220
+
221
+ ### :nan [Symbol]
222
+
223
+ How to dump Infinity, -Infinity, and NaN in :null, :strict, and :compat
224
+ mode. Default is :auto but is ignored in the :compat and :rails modes.
225
+
226
+ - `:null` places a null
227
+
228
+ - `:huge` places a huge number
229
+
230
+ - `:word` places Infinity or NaN
231
+
232
+ - `:raise` raises and exception
233
+
234
+ - `:auto` uses default for each mode which are `:raise` for `:strict`, `:null` for `:null`, and `:word` for `:compat`.
235
+
236
+ ### :nilnil [Boolean]
237
+
238
+ If true a nil input to load will return nil and not raise an Exception.
239
+
240
+ ### :object_class
241
+
242
+ The class to use when creating a Hash on load instead of the Hash class.
243
+
244
+ ### :object_nl
245
+
246
+ Trailer appended to the end of an object dump. The default is an empty
247
+ string. Primarily intended for json gem compatibility. Using just indent as an
248
+ integer gives better performance.
249
+
250
+ ### :omit_nil [Boolean]
251
+
252
+ If true, Hash and Object attributes with nil values are omitted.
253
+
254
+ ### :quirks_mode [Boolean]
255
+
256
+ Allow single JSON values instead of documents, default is true (allow). This
257
+ can also be used in :compat mode to be backward compatible with older versions
258
+ of the json gem.
259
+
260
+ ### :safe
261
+
262
+ The JSON gem includes the complete JSON in parse errors with no limit
263
+ on size. To break from the JSON gem behavior for this case set `:safe`
264
+ to true.
265
+
266
+ ### :second_precision [Fixnum]
267
+
268
+ The number of digits after the decimal when dumping the seconds of time.
269
+
270
+ ### :skip_null_byte [Boolean]
271
+
272
+ If true, null bytes in strings will be omitted when dumping.
273
+
274
+ ### :space
275
+
276
+ String inserted after the ':' character when dumping a JSON object. The
277
+ default is an empty string. Primarily intended for json gem
278
+ compatibility. Using just indent as an integer gives better performance.
279
+
280
+ ### :space_before
281
+
282
+ String inserted before the ':' character when dumping a JSON object. The
283
+ default is an empty string. Primarily intended for json gem
284
+ compatibility. Using just indent as an integer gives better performance.
285
+
286
+ ### :symbol_keys [Boolean]
287
+
288
+ Use symbols instead of strings for hash keys.
289
+
290
+ ### :symbolize_names [Boolean]
291
+
292
+ Like :symbol_keys has keys are made into symbols but only when
293
+ mimicking the JSON gem and then only as the JSON gem honors it so
294
+ JSON.parse honors the option but JSON.load does not.
295
+
296
+ ### :trace
297
+
298
+ When true dump and load functions are traced by printing beginning and ending
299
+ of blocks and of specific calls.
300
+
301
+ ### :time_format [Symbol]
302
+
303
+ The :time_format when dumping.
304
+
305
+ - `:unix` time is output as a decimal number in seconds since epoch including fractions of a second.
306
+
307
+ - `:unix_zone` is similar to the `:unix` format but with the timezone encoded in
308
+ the exponent of the decimal number of seconds since epoch.
309
+
310
+ - `:xmlschema` time is output as a string that follows the XML schema definition.
311
+
312
+ - `:ruby` time is output as a string formatted using the Ruby `to_s` conversion.
313
+
314
+ ### :use_as_json [Boolean]
315
+
316
+ Call `as_json()` methods on dump, default is false. The option is ignored in
317
+ the :compat and :rails modes.
318
+
319
+
320
+ ### :use_raw_json [Boolean]
321
+
322
+ Call `raw_json()` methods on dump, default is false. The option is
323
+ accepted in the :compat and :rails modes even though it is not
324
+ supported by other JSON gems. It provides a means to optimize dump or
325
+ generate performance. The `raw_json(depth, indent)` method should be
326
+ called only by Oj. It is not intended for any other use. This is meant
327
+ to replace the abused `to_json` methods. Calling `Oj.dump` inside the
328
+ `raw_json` with the object itself when `:use_raw_json` is true will
329
+ result in an infinite loop.
330
+
331
+ ### :use_to_hash [Boolean]
332
+
333
+ Call `to_hash()` methods on dump, default is false. The option is ignored in
334
+ the :compat and :rails modes.
335
+
336
+ ### :use_to_json [Boolean]
337
+
338
+ Call `to_json()` methods on dump, default is false. The option is ignored in
339
+ the :compat and :rails modes.