oj 3.10.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +104 -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 +1218 -0
  13. data/ext/oj/dump.c +1249 -0
  14. data/ext/oj/dump.h +96 -0
  15. data/ext/oj/dump_compat.c +975 -0
  16. data/ext/oj/dump_leaf.c +252 -0
  17. data/ext/oj/dump_object.c +844 -0
  18. data/ext/oj/dump_strict.c +434 -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 +53 -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 +890 -0
  28. data/ext/oj/object.c +775 -0
  29. data/ext/oj/odd.c +231 -0
  30. data/ext/oj/odd.h +44 -0
  31. data/ext/oj/oj.c +1723 -0
  32. data/ext/oj/oj.h +387 -0
  33. data/ext/oj/parse.c +1134 -0
  34. data/ext/oj/parse.h +112 -0
  35. data/ext/oj/rails.c +1528 -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 +924 -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 +534 -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 +155 -0
  73. data/pages/Options.md +287 -0
  74. data/pages/Rails.md +155 -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/abstract_unit.rb +45 -0
  85. data/test/activesupport5/decoding_test.rb +133 -0
  86. data/test/activesupport5/encoding_test.rb +500 -0
  87. data/test/activesupport5/encoding_test_cases.rb +98 -0
  88. data/test/activesupport5/test_helper.rb +72 -0
  89. data/test/activesupport5/time_zone_test_helpers.rb +39 -0
  90. data/test/activesupport6/abstract_unit.rb +44 -0
  91. data/test/activesupport6/decoding_test.rb +133 -0
  92. data/test/activesupport6/encoding_test.rb +507 -0
  93. data/test/activesupport6/encoding_test_cases.rb +98 -0
  94. data/test/activesupport6/test_common.rb +17 -0
  95. data/test/activesupport6/test_helper.rb +163 -0
  96. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  97. data/test/bar.rb +35 -0
  98. data/test/baz.rb +16 -0
  99. data/test/files.rb +29 -0
  100. data/test/foo.rb +52 -0
  101. data/test/helper.rb +26 -0
  102. data/test/isolated/shared.rb +308 -0
  103. data/test/isolated/test_mimic_after.rb +13 -0
  104. data/test/isolated/test_mimic_alone.rb +12 -0
  105. data/test/isolated/test_mimic_as_json.rb +45 -0
  106. data/test/isolated/test_mimic_before.rb +13 -0
  107. data/test/isolated/test_mimic_define.rb +28 -0
  108. data/test/isolated/test_mimic_rails_after.rb +22 -0
  109. data/test/isolated/test_mimic_rails_before.rb +21 -0
  110. data/test/isolated/test_mimic_redefine.rb +15 -0
  111. data/test/json_gem/json_addition_test.rb +216 -0
  112. data/test/json_gem/json_common_interface_test.rb +148 -0
  113. data/test/json_gem/json_encoding_test.rb +107 -0
  114. data/test/json_gem/json_ext_parser_test.rb +20 -0
  115. data/test/json_gem/json_fixtures_test.rb +35 -0
  116. data/test/json_gem/json_generator_test.rb +383 -0
  117. data/test/json_gem/json_generic_object_test.rb +90 -0
  118. data/test/json_gem/json_parser_test.rb +470 -0
  119. data/test/json_gem/json_string_matching_test.rb +42 -0
  120. data/test/json_gem/test_helper.rb +18 -0
  121. data/test/perf.rb +107 -0
  122. data/test/perf_compat.rb +130 -0
  123. data/test/perf_fast.rb +164 -0
  124. data/test/perf_file.rb +64 -0
  125. data/test/perf_object.rb +138 -0
  126. data/test/perf_saj.rb +109 -0
  127. data/test/perf_scp.rb +151 -0
  128. data/test/perf_simple.rb +287 -0
  129. data/test/perf_strict.rb +145 -0
  130. data/test/perf_wab.rb +131 -0
  131. data/test/prec.rb +23 -0
  132. data/test/sample.rb +54 -0
  133. data/test/sample/change.rb +14 -0
  134. data/test/sample/dir.rb +19 -0
  135. data/test/sample/doc.rb +36 -0
  136. data/test/sample/file.rb +48 -0
  137. data/test/sample/group.rb +16 -0
  138. data/test/sample/hasprops.rb +16 -0
  139. data/test/sample/layer.rb +12 -0
  140. data/test/sample/line.rb +20 -0
  141. data/test/sample/oval.rb +10 -0
  142. data/test/sample/rect.rb +10 -0
  143. data/test/sample/shape.rb +35 -0
  144. data/test/sample/text.rb +20 -0
  145. data/test/sample_json.rb +37 -0
  146. data/test/test_compat.rb +502 -0
  147. data/test/test_custom.rb +527 -0
  148. data/test/test_debian.rb +53 -0
  149. data/test/test_fast.rb +470 -0
  150. data/test/test_file.rb +239 -0
  151. data/test/test_gc.rb +49 -0
  152. data/test/test_hash.rb +29 -0
  153. data/test/test_integer_range.rb +72 -0
  154. data/test/test_null.rb +376 -0
  155. data/test/test_object.rb +1027 -0
  156. data/test/test_rails.rb +26 -0
  157. data/test/test_saj.rb +186 -0
  158. data/test/test_scp.rb +433 -0
  159. data/test/test_strict.rb +433 -0
  160. data/test/test_various.rb +719 -0
  161. data/test/test_wab.rb +307 -0
  162. data/test/test_writer.rb +380 -0
  163. data/test/tests.rb +25 -0
  164. data/test/tests_mimic.rb +14 -0
  165. data/test/tests_mimic_addition.rb +7 -0
  166. data/test/zoo.rb +13 -0
  167. metadata +381 -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,155 @@
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 determine 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
+ | :safe | String | | | x | | | | |
121
+ | :second_precision | Fixnum | | | | | x | x | |
122
+ | :space | String | | | x | x | | x | |
123
+ | :space_before | String | | | x | x | | x | |
124
+ | :symbol_keys | Boolean | x | x | x | x | x | x | |
125
+ | :trace | Boolean | x | x | x | x | x | x | x |
126
+ | :time_format | Symbol | | | | | x | x | |
127
+ | :use_as_json | Boolean | | | | | | x | |
128
+ | :use_raw_json | Boolean | | | x | x | x | x | |
129
+ | :use_to_hash | Boolean | | | | | | x | |
130
+ | :use_to_json | Boolean | | | | | | x | |
131
+ --------------------------------------------------------------------------------------------------------
132
+
133
+ 1. :allow_blank an alias for :nilnil.
134
+
135
+ 2. The :ascii_only options is an undocumented json gem option.
136
+
137
+ 3. By default the bigdecimal_as decimal is not set and the default encoding
138
+ for Rails is as a string. Setting the value to true will encode a
139
+ BigDecimal as a number which breaks compatibility.
140
+
141
+ 4. The integer indent value in the default options will be honored by since
142
+ the json gem expects a String type the indent in calls to 'to_json()',
143
+ 'Oj.generate()', or 'Oj.generate_fast()' expect a String and not an
144
+ integer.
145
+
146
+ 5. The max_nesting option is for the json gem and rails only. It exists for
147
+ compatibility. For other Oj dump modes the maximum nesting is set to over
148
+ 1000. If reference loops exist in the object being dumped then using the
149
+ `:circular` option is a far better choice. It adds a slight overhead but
150
+ detects an object that appears more than once in a dump and does not dump
151
+ that object a second time.
152
+
153
+ 6. The quirks mode option is no longer supported in the most recent json
154
+ gem. It is supported by Oj for backward compatibility with older json gem
155
+ versions.
@@ -0,0 +1,287 @@
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 that the :create_id key, when encountered during parsing,
84
+ should create an Object matching the class name specified in the value
85
+ associated 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
+ In the `:custom` mode, setting the `:create_id` to nil will cause Complex,
93
+ Rational, Range, and Regexp to be output as strings instead of as JSON
94
+ objects.
95
+
96
+ ### :empty_string [Boolean]
97
+
98
+ If true an empty or all whitespace input will not raise an Exception. The
99
+ default_options will be honored for :null, :strict, and :custom modes. Ignored
100
+ for :custom and :wab. The :compat has a more complex set of rules. The JSON
101
+ gem compatibility is best described by examples.
102
+
103
+ ```
104
+ JSON.parse('') => raise
105
+ JSON.parse(' ') => raise
106
+ JSON.load('') => nil
107
+ JSON.load('', nil, allow_blank: false) => raise
108
+ JSON.load('', nil, allow_blank: true) => nil
109
+ JSON.load(' ') => raise
110
+ JSON.load(' ', nil, allow_blank: false) => raise
111
+ JSON.load(' ', nil, allow_blank: true) => raise
112
+ ```
113
+
114
+ ### :escape_mode [Symbol]
115
+
116
+ Determines the characters to escape when dumping. Only the :ascii and
117
+ :json modes are supported in :compat mode.
118
+
119
+ - `:newline` allows unescaped newlines in the output.
120
+
121
+ - `:json` follows the JSON specification. This is the default mode.
122
+
123
+ - `:xss_safe` escapes HTML and XML characters such as `&` and `<`.
124
+
125
+ - `:ascii` escapes all non-ascii or characters with the hi-bit set.
126
+
127
+ - `:unicode_xss` escapes a special unicodes and is xss safe.
128
+
129
+ ### :float_precision [Fixnum]
130
+
131
+ The number of digits of precision when dumping floats, 0 indicates use Ruby directly.
132
+
133
+ ### :hash_class [Class]
134
+
135
+ Class to use instead of Hash on load. This is the same as the :object_class.
136
+
137
+ ### :ignore [Array]
138
+
139
+ Ignore all the classes in the Array when dumping. A value of nil indicates
140
+ ignore nothing.
141
+
142
+ ### :indent [Fixnum]
143
+
144
+ Number of spaces to indent each element in a JSON document, zero is no newline
145
+ between JSON elements, negative indicates no newline between top level JSON
146
+ elements in a stream.
147
+
148
+ ### :indent_str
149
+
150
+ Indentation for each element when dumping. The default is an empty
151
+ string. Primarily intended for json gem compatibility. Using just indent as an
152
+ integer gives better performance.
153
+
154
+ ### :integer_range [Range]
155
+
156
+ Dump integers outside range as strings.
157
+ Note: range bounds must be Fixnum.
158
+
159
+ ### :match_string
160
+
161
+ Provides a means to detect strings that should be used to create non-String
162
+ objects. The value to the option must be a Hash with keys that are regular
163
+ expressions and values are class names. For strict json gem compatibility a
164
+ RegExp should be used. For better performance but sacrificing some regexp
165
+ options a string can be used and the C version of regex will be used instead.
166
+
167
+ ### :max_nesting
168
+
169
+ The maximum nesting depth on both dump and load that is allowed. This exists
170
+ for json gem compatibility.
171
+
172
+ ### :mode [Symbol]
173
+
174
+ Primary behavior for loading and dumping. The :mode option controls which
175
+ other options are in effect. For more details see the {file:Modes.md} page. By
176
+ default Oj uses the :custom mode which is provides the highest degree of
177
+ customization.
178
+
179
+ ### :nan [Symbol]
180
+
181
+ How to dump Infinity, -Infinity, and NaN in :null, :strict, and :compat
182
+ mode. Default is :auto but is ignored in the :compat and :rails modes.
183
+
184
+ - `:null` places a null
185
+
186
+ - `:huge` places a huge number
187
+
188
+ - `:word` places Infinity or NaN
189
+
190
+ - `:raise` raises and exception
191
+
192
+ - `:auto` uses default for each mode which are `:raise` for `:strict`, `:null` for `:null`, and `:word` for `:compat`.
193
+
194
+ ### :nilnil [Boolean]
195
+
196
+ If true a nil input to load will return nil and not raise an Exception.
197
+
198
+ ### :object_class
199
+
200
+ The class to use when creating a Hash on load instead of the Hash class.
201
+
202
+ ### :object_nl
203
+
204
+ Trailer appended to the end of an object dump. The default is an empty
205
+ string. Primarily intended for json gem compatibility. Using just indent as an
206
+ integer gives better performance.
207
+
208
+ ### :omit_nil [Boolean]
209
+
210
+ If true, Hash and Object attributes with nil values are omitted.
211
+
212
+ ### :quirks_mode [Boolean]
213
+
214
+ Allow single JSON values instead of documents, default is true (allow). This
215
+ can also be used in :compat mode to be backward compatible with older versions
216
+ of the json gem.
217
+
218
+ ### :safe
219
+
220
+ The JSON gem includes the complete JSON in parse errors with no limit
221
+ on size. To break from the JSON gem behavior for this case set `:safe`
222
+ to true.
223
+
224
+ ### :second_precision [Fixnum]
225
+
226
+ The number of digits after the decimal when dumping the seconds of time.
227
+
228
+ ### :space
229
+
230
+ String inserted after the ':' character when dumping a JSON object. The
231
+ default is an empty string. Primarily intended for json gem
232
+ compatibility. Using just indent as an integer gives better performance.
233
+
234
+ ### :space_before
235
+
236
+ String inserted before the ':' character when dumping a JSON object. The
237
+ default is an empty string. Primarily intended for json gem
238
+ compatibility. Using just indent as an integer gives better performance.
239
+
240
+ ### :symbol_keys [Boolean]
241
+
242
+ Use symbols instead of strings for hash keys. :symbolize_names is an alias.
243
+
244
+ ### :trace
245
+
246
+ When true dump and load functions are traced by printing beginning and ending
247
+ of blocks and of specific calls.
248
+
249
+ ### :time_format [Symbol]
250
+
251
+ The :time_format when dumping.
252
+
253
+ - `:unix` time is output as a decimal number in seconds since epoch including fractions of a second.
254
+
255
+ - `:unix_zone` is similar to the `:unix` format but with the timezone encoded in
256
+ the exponent of the decimal number of seconds since epoch.
257
+
258
+ - `:xmlschema` time is output as a string that follows the XML schema definition.
259
+
260
+ - `:ruby` time is output as a string formatted using the Ruby `to_s` conversion.
261
+
262
+ ### :use_as_json [Boolean]
263
+
264
+ Call `as_json()` methods on dump, default is false. The option is ignored in
265
+ the :compat and :rails modes.
266
+
267
+
268
+ ### :use_raw_json [Boolean]
269
+
270
+ Call `raw_json()` methods on dump, default is false. The option is
271
+ accepted in the :compat and :rails modes even though it is not
272
+ supported by other JSON gems. It provides a means to optimize dump or
273
+ generate performance. The `raw_json(depth, indent)` method should be
274
+ called only by Oj. It is not intended for any other use. This is meant
275
+ to replace the abused `to_json` methods. Calling `Oj.dump` inside the
276
+ `raw_json` with the object itself when `:use_raw_json` is true will
277
+ result in an infinite loop.
278
+
279
+ ### :use_to_hash [Boolean]
280
+
281
+ Call `to_hash()` methods on dump, default is false. The option is ignored in
282
+ the :compat and :rails modes.
283
+
284
+ ### :use_to_json [Boolean]
285
+
286
+ Call `to_json()` methods on dump, default is false. The option is ignored in
287
+ the :compat and :rails modes.