oj 3.7.12

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 (156) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +96 -0
  4. data/ext/oj/buf.h +103 -0
  5. data/ext/oj/cache8.c +107 -0
  6. data/ext/oj/cache8.h +48 -0
  7. data/ext/oj/circarray.c +68 -0
  8. data/ext/oj/circarray.h +23 -0
  9. data/ext/oj/code.c +235 -0
  10. data/ext/oj/code.h +42 -0
  11. data/ext/oj/compat.c +299 -0
  12. data/ext/oj/custom.c +1188 -0
  13. data/ext/oj/dump.c +1232 -0
  14. data/ext/oj/dump.h +94 -0
  15. data/ext/oj/dump_compat.c +973 -0
  16. data/ext/oj/dump_leaf.c +252 -0
  17. data/ext/oj/dump_object.c +837 -0
  18. data/ext/oj/dump_strict.c +433 -0
  19. data/ext/oj/encode.h +45 -0
  20. data/ext/oj/err.c +57 -0
  21. data/ext/oj/err.h +70 -0
  22. data/ext/oj/extconf.rb +47 -0
  23. data/ext/oj/fast.c +1771 -0
  24. data/ext/oj/hash.c +163 -0
  25. data/ext/oj/hash.h +46 -0
  26. data/ext/oj/hash_test.c +512 -0
  27. data/ext/oj/mimic_json.c +873 -0
  28. data/ext/oj/object.c +771 -0
  29. data/ext/oj/odd.c +231 -0
  30. data/ext/oj/odd.h +44 -0
  31. data/ext/oj/oj.c +1694 -0
  32. data/ext/oj/oj.h +381 -0
  33. data/ext/oj/parse.c +1085 -0
  34. data/ext/oj/parse.h +111 -0
  35. data/ext/oj/rails.c +1485 -0
  36. data/ext/oj/rails.h +21 -0
  37. data/ext/oj/reader.c +231 -0
  38. data/ext/oj/reader.h +151 -0
  39. data/ext/oj/resolve.c +102 -0
  40. data/ext/oj/resolve.h +14 -0
  41. data/ext/oj/rxclass.c +147 -0
  42. data/ext/oj/rxclass.h +27 -0
  43. data/ext/oj/saj.c +714 -0
  44. data/ext/oj/scp.c +224 -0
  45. data/ext/oj/sparse.c +910 -0
  46. data/ext/oj/stream_writer.c +363 -0
  47. data/ext/oj/strict.c +212 -0
  48. data/ext/oj/string_writer.c +512 -0
  49. data/ext/oj/trace.c +79 -0
  50. data/ext/oj/trace.h +28 -0
  51. data/ext/oj/util.c +136 -0
  52. data/ext/oj/util.h +19 -0
  53. data/ext/oj/val_stack.c +118 -0
  54. data/ext/oj/val_stack.h +185 -0
  55. data/ext/oj/wab.c +631 -0
  56. data/lib/oj.rb +21 -0
  57. data/lib/oj/active_support_helper.rb +41 -0
  58. data/lib/oj/bag.rb +88 -0
  59. data/lib/oj/easy_hash.rb +52 -0
  60. data/lib/oj/error.rb +22 -0
  61. data/lib/oj/json.rb +176 -0
  62. data/lib/oj/mimic.rb +267 -0
  63. data/lib/oj/saj.rb +66 -0
  64. data/lib/oj/schandler.rb +142 -0
  65. data/lib/oj/state.rb +131 -0
  66. data/lib/oj/version.rb +5 -0
  67. data/pages/Advanced.md +22 -0
  68. data/pages/Compatibility.md +25 -0
  69. data/pages/Custom.md +23 -0
  70. data/pages/Encoding.md +65 -0
  71. data/pages/JsonGem.md +79 -0
  72. data/pages/Modes.md +154 -0
  73. data/pages/Options.md +266 -0
  74. data/pages/Rails.md +116 -0
  75. data/pages/Security.md +20 -0
  76. data/pages/WAB.md +13 -0
  77. data/test/_test_active.rb +76 -0
  78. data/test/_test_active_mimic.rb +96 -0
  79. data/test/_test_mimic_rails.rb +126 -0
  80. data/test/activerecord/result_test.rb +27 -0
  81. data/test/activesupport4/decoding_test.rb +108 -0
  82. data/test/activesupport4/encoding_test.rb +531 -0
  83. data/test/activesupport4/test_helper.rb +41 -0
  84. data/test/activesupport5/decoding_test.rb +125 -0
  85. data/test/activesupport5/encoding_test.rb +485 -0
  86. data/test/activesupport5/encoding_test_cases.rb +90 -0
  87. data/test/activesupport5/test_helper.rb +50 -0
  88. data/test/activesupport5/time_zone_test_helpers.rb +24 -0
  89. data/test/big.rb +15 -0
  90. data/test/files.rb +29 -0
  91. data/test/foo.rb +33 -0
  92. data/test/helper.rb +26 -0
  93. data/test/isolated/shared.rb +308 -0
  94. data/test/isolated/test_mimic_after.rb +13 -0
  95. data/test/isolated/test_mimic_alone.rb +12 -0
  96. data/test/isolated/test_mimic_as_json.rb +45 -0
  97. data/test/isolated/test_mimic_before.rb +13 -0
  98. data/test/isolated/test_mimic_define.rb +28 -0
  99. data/test/isolated/test_mimic_rails_after.rb +22 -0
  100. data/test/isolated/test_mimic_rails_before.rb +21 -0
  101. data/test/isolated/test_mimic_redefine.rb +15 -0
  102. data/test/json_gem/json_addition_test.rb +216 -0
  103. data/test/json_gem/json_common_interface_test.rb +148 -0
  104. data/test/json_gem/json_encoding_test.rb +107 -0
  105. data/test/json_gem/json_ext_parser_test.rb +20 -0
  106. data/test/json_gem/json_fixtures_test.rb +35 -0
  107. data/test/json_gem/json_generator_test.rb +383 -0
  108. data/test/json_gem/json_generic_object_test.rb +90 -0
  109. data/test/json_gem/json_parser_test.rb +470 -0
  110. data/test/json_gem/json_string_matching_test.rb +42 -0
  111. data/test/json_gem/test_helper.rb +18 -0
  112. data/test/mem.rb +35 -0
  113. data/test/perf.rb +107 -0
  114. data/test/perf_compat.rb +130 -0
  115. data/test/perf_fast.rb +164 -0
  116. data/test/perf_file.rb +64 -0
  117. data/test/perf_object.rb +138 -0
  118. data/test/perf_saj.rb +109 -0
  119. data/test/perf_scp.rb +151 -0
  120. data/test/perf_simple.rb +287 -0
  121. data/test/perf_strict.rb +145 -0
  122. data/test/perf_wab.rb +131 -0
  123. data/test/sample.rb +54 -0
  124. data/test/sample/change.rb +14 -0
  125. data/test/sample/dir.rb +19 -0
  126. data/test/sample/doc.rb +36 -0
  127. data/test/sample/file.rb +48 -0
  128. data/test/sample/group.rb +16 -0
  129. data/test/sample/hasprops.rb +16 -0
  130. data/test/sample/layer.rb +12 -0
  131. data/test/sample/line.rb +20 -0
  132. data/test/sample/oval.rb +10 -0
  133. data/test/sample/rect.rb +10 -0
  134. data/test/sample/shape.rb +35 -0
  135. data/test/sample/text.rb +20 -0
  136. data/test/sample_json.rb +37 -0
  137. data/test/test_compat.rb +509 -0
  138. data/test/test_custom.rb +406 -0
  139. data/test/test_debian.rb +53 -0
  140. data/test/test_fast.rb +470 -0
  141. data/test/test_file.rb +239 -0
  142. data/test/test_gc.rb +49 -0
  143. data/test/test_hash.rb +29 -0
  144. data/test/test_integer_range.rb +73 -0
  145. data/test/test_null.rb +376 -0
  146. data/test/test_object.rb +1018 -0
  147. data/test/test_saj.rb +186 -0
  148. data/test/test_scp.rb +433 -0
  149. data/test/test_strict.rb +410 -0
  150. data/test/test_various.rb +739 -0
  151. data/test/test_wab.rb +307 -0
  152. data/test/test_writer.rb +380 -0
  153. data/test/tests.rb +24 -0
  154. data/test/tests_mimic.rb +14 -0
  155. data/test/tests_mimic_addition.rb +7 -0
  156. metadata +359 -0
@@ -0,0 +1,79 @@
1
+ # Oj JSON Gem Compatibility
2
+
3
+ The `:compat` mode mimics the json gem. The json gem is built around the use
4
+ of the `to_json(*)` method defined for a class. Oj attempts to provide the
5
+ same functionality by being a drop in replacement for the 2.0.x version of the
6
+ json gem with a few exceptions. First a description of the json gem behavior
7
+ and then the differences between the json gem and the Oj.mimic_JSON behavior.
8
+
9
+ ```ruby
10
+ require 'oj'
11
+
12
+ Oj.mimic_JSON()
13
+ Oj.add_to_json(Array, BigDecimal, Complex, Date, DateTime, Exception, Hash, Integer, OpenStruct, Range, Rational, Regexp, Struct, Time)
14
+ # Alternativel just call without arguments to add all available.
15
+ # Oj.add_to_json()
16
+ ```
17
+
18
+ The json gem monkey patches core and base library classes with a `to_json(*)`
19
+ method. This allows calls such as `obj.to_json()` to be used to generate a
20
+ JSON string. The json gem also provides the JSON.generate(), JSON.dump(), and
21
+ JSON() functions. These functions generally act the same with some exceptions
22
+ such as JSON.generate(), JSON(), and to_json raise an exception when
23
+ attempting to encode infinity while JSON.dump() returns a the string
24
+ "Infinity". The String class is also monkey patched with to_json_raw() and
25
+ to_json_raw_object(). Oj in mimic mode mimics this behavior including the
26
+ seemly inconsistent behavior with NaN and Infinity.
27
+
28
+ Any class can define a to_json() method and JSON.generate(), JSON.dump(), and
29
+ JSON() functions will call that method when an object of that type is
30
+ encountered when traversing a Hash or Array. The core classes monkey patches
31
+ can be over-ridden but unless the to_json() method is called directory the
32
+ to_json() method will be ignored. Oj in mimic mode follow the same logic,
33
+
34
+ The json gem includes additions. These additions change the behavior of some
35
+ library and core classes. These additions also add the as_json() method and
36
+ json_create() class method. They are activated by requiring the appropriate
37
+ files. As an example, to get the modified to_json() for the Rational class
38
+ this line would be added.
39
+
40
+ ```ruby
41
+ require 'json/add/rational'
42
+ ```
43
+
44
+ Oj in mimic mode does not include these files although it will support the
45
+ modified to_json() methods. In keeping with the goal of providing a faster
46
+ encoder Oj offers an alternative. To activate faster addition version of the
47
+ to_json() method call
48
+
49
+ ```ruby
50
+ Oj.add_to_json(Rational)
51
+ ```
52
+
53
+ To revert back to the unoptimized version, just remove the Oj flag on that
54
+ class.
55
+
56
+ ```ruby
57
+ Oj.remove_to_json(Rational)
58
+ ```
59
+
60
+ The classes that can be added are:
61
+
62
+ * Array
63
+ * BigDecimal
64
+ * Complex
65
+ * Date
66
+ * DateTime
67
+ * Exception
68
+ * Hash
69
+ * Integer
70
+ * OpenStruct
71
+ * Range
72
+ * Rational
73
+ * Regexp
74
+ * Struct
75
+ * Time
76
+
77
+ The compatibility target version is 2.0.3. The json gem unit tests were used
78
+ to verify compatibility with a few changes to use Oj instead of the original
79
+ gem.
@@ -0,0 +1,154 @@
1
+ # Oj Modes
2
+
3
+ Oj uses modes to switch the load and dump behavior. Initially Oj supported on
4
+ the :object mode which uses a format that allows Ruby object encoding and
5
+ decoding in a manner that lets almost any Ruby object be encoded and decoded
6
+ without monkey patching the object classes. From that start other demands were
7
+ made the were best met by giving Oj multiple modes of operation. The current
8
+ modes are:
9
+
10
+ - `:strict`
11
+ - `:null`
12
+ - `:compat` or `:json`
13
+ - `:rails`
14
+ - `:object`
15
+ - `:custom`
16
+
17
+ Since modes detemine what the JSON output will look like and alternatively
18
+ what Oj expects when the `Oj.load()` method is called, mixing the output and
19
+ input mode formats will most likely not behave as intended. If the object mode
20
+ is used for producing JSON then use object mode for reading. The same is true
21
+ for each mode. It is possible to mix but only for advanced users.
22
+
23
+ ## :strict Mode
24
+
25
+ Strict mode follows the JSON specifications and only supports the JSON native
26
+ types, Boolean, nil, String, Hash, Array, and Numbers are encoded as
27
+ expected. Encountering any other type causes an Exception to be raised. This
28
+ is the safest mode as it is just simple translation, no code outside Oj or the
29
+ core Ruby is execution on loading. Very few options are supported by this mode
30
+ other than formatting options.
31
+
32
+ ## :null Mode
33
+
34
+ Null mode is similar to the :strict mode except that a JSON null is inserted
35
+ if a non-native type is encountered instead of raising an Exception.
36
+
37
+ ## :compat or :json Mode
38
+
39
+ The `:compat` mode mimics the json gem. The json gem is built around the use
40
+ of the `to_json(*)` method defined for a class. Oj attempts to provide the
41
+ same functionality by being a drop in replacement with a few
42
+ exceptions. [{file:JsonGem.md}](JsonGem.md) includes more details on
43
+ compatibility and use.
44
+
45
+ ## :rails Mode
46
+
47
+ The `:rails` mode mimics the ActiveSupport version 5 encoder. Rails and
48
+ ActiveSupport are built around the use of the `as_json(*)` method defined for
49
+ a class. Oj attempts to provide the same functionality by being a drop in
50
+ replacement with a few exceptions. [{file:Rails.md}](Rails.md) includes
51
+ more details on compatibility and use.
52
+
53
+ ## :object Mode
54
+
55
+ Object mode is for fast Ruby object serialization and deserialization. That
56
+ was the primary purpose of Oj when it was first developed. As such it is the
57
+ default mode unless changed in the Oj default options. In :object mode Oj
58
+ generates JSON that follows conventions which allow Class and other
59
+ information such as Object IDs for circular reference detection to be encoded
60
+ in a JSON document. The formatting follows the rules describe on the
61
+ [{file:Encoding.md}](Encoding.md) page.
62
+
63
+ ## :custom Mode
64
+
65
+ Custom mode honors all options. It provides the most flexibility although it
66
+ can not be configured to be exactly like any of the other modes. Each mode has
67
+ some special aspect that makes it unique. For example, the `:object` mode has
68
+ it's own unique format for object dumping and loading. The `:compat` mode
69
+ mimic the json gem including methods called for encoding and inconsistencies
70
+ between `JSON.dump()`, `JSON.generate()`, and `JSON()`. More details on the
71
+ [{file:Custom.md}](Custom.md) page.
72
+
73
+ ## :wab Mode
74
+
75
+ WAB mode ignores all options except the indent option. Performance of this
76
+ mode is on slightly better than the :strict and :null modes. It is included to
77
+ support the [WABuR](https://github.com/ohler55/wabur) project. More details on
78
+ the [{file:WAB.md}](WAB.md) page.
79
+
80
+ ## Options Matrix
81
+
82
+ Not all options are available in all modes. The options matrix identifies the
83
+ options available in each mode. An `x` in the matrix indicates the option is
84
+ supported in that mode. A number indicates the footnotes describe additional
85
+ information.
86
+
87
+ | Option | type | :null | :strict | :compat | :rails | :object | :custom | :wab |
88
+ | ---------------------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |
89
+ | :allow_blank | Boolean | | | 1 | 1 | | x | |
90
+ | :allow_gc | Boolean | x | x | x | x | x | x | |
91
+ | :allow_invalid_unicode | Boolean | | | | | x | x | |
92
+ | :allow_nan | Boolean | | | x | | x | x | |
93
+ | :array_class | Class | | | x | x | | x | |
94
+ | :array_nl | String | | | | | | x | |
95
+ | :ascii_only | Boolean | x | x | 2 | 2 | x | x | |
96
+ | :auto_define | Boolean | | | | | x | x | |
97
+ | :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | |
98
+ | :bigdecimal_load | Boolean | | | | | | x | |
99
+ | :circular | Boolean | x | x | x | x | x | x | |
100
+ | :class_cache | Boolean | | | | | x | x | |
101
+ | :create_additions | Boolean | | | x | x | | x | |
102
+ | :create_id | String | | | x | x | | x | |
103
+ | :empty_string | Boolean | | | | | | x | |
104
+ | :escape_mode | Symbol | | | | | | x | |
105
+ | :float_precision | Fixnum | x | x | | | | x | |
106
+ | :hash_class | Class | | | x | x | | x | |
107
+ | :ignore | Array | | | | | x | x | |
108
+ | :indent | Integer | x | x | 3 | 4 | x | x | x |
109
+ | :indent_str | String | | | x | x | | x | |
110
+ | :integer_range | Range | x | x | x | x | x | x | x |
111
+ | :match_string | Hash | | | x | x | | x | |
112
+ | :max_nesting | Fixnum | 4 | 4 | x | | 5 | 4 | |
113
+ | :mode | Symbol | - | - | - | - | - | - | |
114
+ | :nan | Symbol | | | | | | x | |
115
+ | :nilnil | Boolean | | | | | | x | |
116
+ | :object_class | Class | | | x | | | x | |
117
+ | :object_nl | String | | | x | x | | x | |
118
+ | :omit_nil | Boolean | x | x | x | x | x | x | |
119
+ | :quirks_mode | Boolean | | | 6 | | | x | |
120
+ | :second_precision | Fixnum | | | | | x | x | |
121
+ | :space | String | | | x | x | | x | |
122
+ | :space_before | String | | | x | x | | x | |
123
+ | :symbol_keys | Boolean | x | x | x | x | x | x | |
124
+ | :trace | Boolean | x | x | x | x | x | x | x |
125
+ | :time_format | Symbol | | | | | x | x | |
126
+ | :use_as_json | Boolean | | | | | | x | |
127
+ | :use_to_hash | Boolean | | | | | | x | |
128
+ | :use_to_json | Boolean | | | | | | x | |
129
+ --------------------------------------------------------------------------------------------------------
130
+
131
+ 1. :allow_blank an alias for :nilnil.
132
+
133
+ 2. The :ascii_only options is an undocumented json gem option.
134
+
135
+ 3. By default the bigdecimal_as decimal is not set and the default encoding
136
+ for Rails is as a string. Setting the value to true will encode a
137
+ BigDecimal as a number which breaks compatibility.
138
+
139
+ 4. The integer indent value in the default options will be honored by since
140
+ the json gem expects a String type the indent in calls to 'to_json()',
141
+ 'Oj.generate()', or 'Oj.generate_fast()' expect a String and not an
142
+ integer.
143
+
144
+ 5. The max_nesting option is for the json gem and rails only. It exists for
145
+ compatibility. For other Oj dump modes the maximum nesting is set to over
146
+ 1000. If reference loops exist in the object being dumped then using the
147
+ `:circular` option is a far better choice. It adds a slight overhead but
148
+ detects an object that appears more than once in a dump and does not dump
149
+ that object a second time.
150
+
151
+ 6. The quirks mode option is no longer supported in the most recent json
152
+ gem. It is supported by Oj for backward compatibility with older json gem
153
+ versions.
154
+
@@ -0,0 +1,266 @@
1
+ # Oj Options
2
+
3
+ To change default serialization mode use the following form. Attempting to
4
+ modify the Oj.default_options Hash directly will not set the changes on the
5
+ actual default options but on a copy of the Hash:
6
+
7
+ ```ruby
8
+ Oj.default_options = {:mode => :compat }
9
+ ```
10
+
11
+ Another way to make use of options when calling load or dump methods is to
12
+ pass in a Hash with the options already set in the Hash. This is slightly less
13
+ efficient than setting the globals for many smaller JSON documents but does
14
+ provide a more thread safe approach to using custom options for loading and
15
+ dumping.
16
+
17
+ ### Options for serializer and parser
18
+
19
+ ### :allow_blank [Boolean]
20
+
21
+ If true a nil input to load will return nil and not raise an Exception.
22
+
23
+ ### :allow_gc [Boolean]
24
+
25
+ Allow or prohibit GC during parsing, default is true (allow).
26
+
27
+ ### :allow_invalid_unicode [Boolean]
28
+
29
+ Allow invalid unicode, default is false (don't allow).
30
+
31
+ ### :allow_nan
32
+
33
+ Alias for the :nan option.
34
+
35
+ ### :array_class [Class]
36
+
37
+ Class to use instead of Array on load.
38
+
39
+ ### :array_nl
40
+
41
+ Trailer appended to the end of an array dump. The default is an empty
42
+ string. Primarily intended for json gem compatibility. Using just indent as an
43
+ integer gives better performance.
44
+
45
+ ### :ascii_only
46
+
47
+ If true all non-ASCII character are escaped when dumping. This is the same as
48
+ setting the :escape_mode options to :ascii and exists for json gem
49
+ compatibility.
50
+
51
+ ### :auto_define [Boolean]
52
+
53
+ Automatically define classes if they do not exist.
54
+
55
+ ### :bigdecimal_as_decimal [Boolean]
56
+
57
+ If true dump BigDecimal as a decimal number otherwise as a String
58
+
59
+ ### :bigdecimal_load [Symbol]
60
+
61
+ Determines how to load decimals.
62
+
63
+ - `:bigdecimal` convert all decimal numbers to BigDecimal.
64
+
65
+ - `:float` convert all decimal numbers to Float.
66
+
67
+ - `:auto` the most precise for the number of digits is used.
68
+
69
+ ### :circular [Boolean]
70
+
71
+ Detect circular references while dumping. In :compat mode raise a
72
+ NestingError. For other modes except the :object mode place a null in the
73
+ output. For :object mode place references in the output that will be used to
74
+ recreate the looped references on load.
75
+
76
+ ### :class_cache [Boolean]
77
+
78
+ Cache classes for faster parsing. This option should not be used if
79
+ dynamically modifying classes or reloading classes then don't use this.
80
+
81
+ ### :create_additions
82
+
83
+ A flag indicating the :create_id key when encountered during parsing should
84
+ creating an Object mactching the class name specified in the value associated
85
+ with the key.
86
+
87
+ ### :create_id [String]
88
+
89
+ The :create_id option specifies that key is used for dumping and loading when
90
+ specifying the class for an encoded object. The default is `json_create`.
91
+
92
+ ### :empty_string [Boolean]
93
+
94
+ If true an empty or all whitespace input will not raise an Exception. The
95
+ default_options will be honored for :null, :strict, and :custom modes. Ignored
96
+ for :custom and :wab. The :compat has a more complex set of rules. The JSON
97
+ gem compatibility is best described by examples.
98
+
99
+ ```
100
+ JSON.parse('') => raise
101
+ JSON.parse(' ') => raise
102
+ JSON.load('') => nil
103
+ JSON.load('', nil, allow_blank: false) => raise
104
+ JSON.load('', nil, allow_blank: true) => nil
105
+ JSON.load(' ') => raise
106
+ JSON.load(' ', nil, allow_blank: false) => raise
107
+ JSON.load(' ', nil, allow_blank: true) => raise
108
+ ```
109
+
110
+ ### :escape_mode [Symbol]
111
+
112
+ Determines the characters to escape when dumping. Only the :ascii and
113
+ :json modes are supported in :compat mode.
114
+
115
+ - `:newline` allows unescaped newlines in the output.
116
+
117
+ - `:json` follows the JSON specification. This is the default mode.
118
+
119
+ - `:xss_safe` escapes HTML and XML characters such as `&` and `<`.
120
+
121
+ - `:ascii` escapes all non-ascii or characters with the hi-bit set.
122
+
123
+ - `:unicode_xss` escapes a special unicodes and is xss safe.
124
+
125
+ ### :float_precision [Fixnum]
126
+
127
+ The number of digits of precision when dumping floats, 0 indicates use Ruby directly.
128
+
129
+ ### :hash_class [Class]
130
+
131
+ Class to use instead of Hash on load. This is the same as the :object_class.
132
+
133
+ ### :ignore [Array]
134
+
135
+ Ignore all the classes in the Array when dumping. A value of nil indicates
136
+ ignore nothing.
137
+
138
+ ### :indent [Fixnum]
139
+
140
+ Number of spaces to indent each element in a JSON document, zero is no newline
141
+ between JSON elements, negative indicates no newline between top level JSON
142
+ elements in a stream.
143
+
144
+ ### :indent_str
145
+
146
+ Indentation for each element when dumping. The default is an empty
147
+ string. Primarily intended for json gem compatibility. Using just indent as an
148
+ integer gives better performance.
149
+
150
+ ### :integer_range [Range]
151
+
152
+ Dump integers outside range as strings.
153
+ Note: range bounds must be Fixnum.
154
+
155
+ ### :match_string
156
+
157
+ Provides a means to detect strings that should be used to create non-String
158
+ objects. The value to the option must be a Hash with keys that are regular
159
+ expressions and values are class names. For strict json gem compatibility a
160
+ RegExp should be used. For better performance but sacrificing some regexp
161
+ options a string can be used and the C version of regex will be used instead.
162
+
163
+ ### :max_nesting
164
+
165
+ The maximum nesting depth on both dump and load that is allowed. This exists
166
+ for json gem compatibility.
167
+
168
+ ### :mode [Symbol]
169
+
170
+ Primary behavior for loading and dumping. The :mode option controls which
171
+ other options are in effect. For more details see the {file:Modes.md} page. By
172
+ default Oj uses the :custom mode which is provides the highest degree of
173
+ customization.
174
+
175
+ ### :nan [Symbol]
176
+
177
+ How to dump Infinity, -Infinity, and NaN in :null, :strict, and :compat
178
+ mode. Default is :auto but is ignored in the :compat and :rails mode.
179
+
180
+ - `:null` places a null
181
+
182
+ - `:huge` places a huge number
183
+
184
+ - `:word` places Infinity or NaN
185
+
186
+ - `:raise` raises and exception
187
+
188
+ - `:auto` uses default for each mode which are `:raise` for `:strict`, `:null` for `:null`, and `:word` for `:compat`.
189
+
190
+ ### :nilnil [Boolean]
191
+
192
+ If true a nil input to load will return nil and not raise an Exception.
193
+
194
+ ### :object_class
195
+
196
+ The class to use when creating a Hash on load instead of the Hash class.
197
+
198
+ ### :object_nl
199
+
200
+ Trailer appended to the end of an object dump. The default is an empty
201
+ string. Primarily intended for json gem compatibility. Using just indent as an
202
+ integer gives better performance.
203
+
204
+ ### :omit_nil [Boolean]
205
+
206
+ If true, Hash and Object attributes with nil values are omitted.
207
+
208
+ ### :quirks_mode [Boolean]
209
+
210
+ Allow single JSON values instead of documents, default is true (allow). This
211
+ can also be used in :compat mode to be backward compatible with older versions
212
+ of the json gem.
213
+
214
+ ### :second_precision [Fixnum]
215
+
216
+ The number of digits after the decimal when dumping the seconds of time.
217
+
218
+ ### :space
219
+
220
+ String inserted after the ':' character when dumping a JSON object. The
221
+ default is an empty string. Primarily intended for json gem
222
+ compatibility. Using just indent as an integer gives better performance.
223
+
224
+ ### :space_before
225
+
226
+ String inserted before the ':' character when dumping a JSON object. The
227
+ default is an empty string. Primarily intended for json gem
228
+ compatibility. Using just indent as an integer gives better performance.
229
+
230
+ ### :symbol_keys [Boolean]
231
+
232
+ Use symbols instead of strings for hash keys. :symbolize_names is an alias.
233
+
234
+ ### :trace
235
+
236
+ When true dump and load functions are traced by printing beginning and ending
237
+ of blocks and of specific calls.
238
+
239
+ ### :time_format [Symbol]
240
+
241
+ The :time_format when dumping.
242
+
243
+ - `:unix` time is output as a decimal number in seconds since epoch including fractions of a second.
244
+
245
+ - `:unix_zone` similar to the `:unix` format but with the timezone encoded in
246
+ the exponent of the decimal number of seconds since epoch.
247
+
248
+ - `:xmlschema` time is output as a string that follows the XML schema definition.
249
+
250
+ - `:ruby` time is output as a string formatted using the Ruby `to_s` conversion.
251
+
252
+ ### :use_as_json [Boolean]
253
+
254
+ Call `as_json()` methods on dump, default is false. The option is ignored in
255
+ the :compat and :rails mode.
256
+
257
+ ### :use_to_hash [Boolean]
258
+
259
+ Call `to_hash()` methods on dump, default is false. The option is ignored in
260
+ the :compat and :rails mode.
261
+
262
+ ### :use_to_json [Boolean]
263
+
264
+ Call `to_json()` methods on dump, default is false. The option is ignored in
265
+ the :compat and :rails mode.
266
+