oj 3.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +104 -0
- data/ext/oj/buf.h +103 -0
- data/ext/oj/cache8.c +107 -0
- data/ext/oj/cache8.h +48 -0
- data/ext/oj/circarray.c +68 -0
- data/ext/oj/circarray.h +23 -0
- data/ext/oj/code.c +235 -0
- data/ext/oj/code.h +42 -0
- data/ext/oj/compat.c +299 -0
- data/ext/oj/custom.c +1191 -0
- data/ext/oj/dump.c +1252 -0
- data/ext/oj/dump.h +96 -0
- data/ext/oj/dump_compat.c +977 -0
- data/ext/oj/dump_leaf.c +252 -0
- data/ext/oj/dump_object.c +837 -0
- data/ext/oj/dump_strict.c +433 -0
- data/ext/oj/encode.h +45 -0
- data/ext/oj/err.c +57 -0
- data/ext/oj/err.h +70 -0
- data/ext/oj/extconf.rb +47 -0
- data/ext/oj/fast.c +1771 -0
- data/ext/oj/hash.c +163 -0
- data/ext/oj/hash.h +46 -0
- data/ext/oj/hash_test.c +512 -0
- data/ext/oj/mimic_json.c +878 -0
- data/ext/oj/object.c +771 -0
- data/ext/oj/odd.c +231 -0
- data/ext/oj/odd.h +44 -0
- data/ext/oj/oj.c +1704 -0
- data/ext/oj/oj.h +385 -0
- data/ext/oj/parse.c +1086 -0
- data/ext/oj/parse.h +111 -0
- data/ext/oj/rails.c +1493 -0
- data/ext/oj/rails.h +21 -0
- data/ext/oj/reader.c +231 -0
- data/ext/oj/reader.h +151 -0
- data/ext/oj/resolve.c +102 -0
- data/ext/oj/resolve.h +14 -0
- data/ext/oj/rxclass.c +147 -0
- data/ext/oj/rxclass.h +27 -0
- data/ext/oj/saj.c +714 -0
- data/ext/oj/scp.c +224 -0
- data/ext/oj/sparse.c +910 -0
- data/ext/oj/stream_writer.c +363 -0
- data/ext/oj/strict.c +212 -0
- data/ext/oj/string_writer.c +534 -0
- data/ext/oj/trace.c +79 -0
- data/ext/oj/trace.h +28 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +19 -0
- data/ext/oj/val_stack.c +118 -0
- data/ext/oj/val_stack.h +185 -0
- data/ext/oj/wab.c +631 -0
- data/lib/oj.rb +21 -0
- data/lib/oj/active_support_helper.rb +41 -0
- data/lib/oj/bag.rb +88 -0
- data/lib/oj/easy_hash.rb +52 -0
- data/lib/oj/error.rb +22 -0
- data/lib/oj/json.rb +176 -0
- data/lib/oj/mimic.rb +267 -0
- data/lib/oj/saj.rb +66 -0
- data/lib/oj/schandler.rb +142 -0
- data/lib/oj/state.rb +131 -0
- data/lib/oj/version.rb +5 -0
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/JsonGem.md +79 -0
- data/pages/Modes.md +155 -0
- data/pages/Options.md +283 -0
- data/pages/Rails.md +116 -0
- data/pages/Security.md +20 -0
- data/pages/WAB.md +13 -0
- data/test/_test_active.rb +76 -0
- data/test/_test_active_mimic.rb +96 -0
- data/test/_test_mimic_rails.rb +126 -0
- data/test/activerecord/result_test.rb +27 -0
- data/test/activesupport4/decoding_test.rb +108 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/decoding_test.rb +125 -0
- data/test/activesupport5/encoding_test.rb +485 -0
- data/test/activesupport5/encoding_test_cases.rb +90 -0
- data/test/activesupport5/test_helper.rb +50 -0
- data/test/activesupport5/time_zone_test_helpers.rb +24 -0
- data/test/bar.rb +25 -0
- data/test/files.rb +29 -0
- data/test/foo.rb +167 -0
- data/test/helper.rb +26 -0
- data/test/isolated/shared.rb +308 -0
- data/test/isolated/test_mimic_after.rb +13 -0
- data/test/isolated/test_mimic_alone.rb +12 -0
- data/test/isolated/test_mimic_as_json.rb +45 -0
- data/test/isolated/test_mimic_before.rb +13 -0
- data/test/isolated/test_mimic_define.rb +28 -0
- data/test/isolated/test_mimic_rails_after.rb +22 -0
- data/test/isolated/test_mimic_rails_before.rb +21 -0
- data/test/isolated/test_mimic_redefine.rb +15 -0
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +148 -0
- data/test/json_gem/json_encoding_test.rb +107 -0
- data/test/json_gem/json_ext_parser_test.rb +20 -0
- data/test/json_gem/json_fixtures_test.rb +35 -0
- data/test/json_gem/json_generator_test.rb +383 -0
- data/test/json_gem/json_generic_object_test.rb +90 -0
- data/test/json_gem/json_parser_test.rb +470 -0
- data/test/json_gem/json_string_matching_test.rb +42 -0
- data/test/json_gem/test_helper.rb +18 -0
- data/test/perf.rb +107 -0
- data/test/perf_compat.rb +130 -0
- data/test/perf_fast.rb +164 -0
- data/test/perf_file.rb +64 -0
- data/test/perf_object.rb +138 -0
- data/test/perf_saj.rb +109 -0
- data/test/perf_scp.rb +151 -0
- data/test/perf_simple.rb +287 -0
- data/test/perf_strict.rb +145 -0
- data/test/perf_wab.rb +131 -0
- data/test/sample.rb +54 -0
- data/test/sample/change.rb +14 -0
- data/test/sample/dir.rb +19 -0
- data/test/sample/doc.rb +36 -0
- data/test/sample/file.rb +48 -0
- data/test/sample/group.rb +16 -0
- data/test/sample/hasprops.rb +16 -0
- data/test/sample/layer.rb +12 -0
- data/test/sample/line.rb +20 -0
- data/test/sample/oval.rb +10 -0
- data/test/sample/rect.rb +10 -0
- data/test/sample/shape.rb +35 -0
- data/test/sample/text.rb +20 -0
- data/test/sample_json.rb +37 -0
- data/test/test_compat.rb +509 -0
- data/test/test_custom.rb +503 -0
- data/test/test_debian.rb +53 -0
- data/test/test_fast.rb +470 -0
- data/test/test_file.rb +239 -0
- data/test/test_gc.rb +49 -0
- data/test/test_hash.rb +29 -0
- data/test/test_integer_range.rb +73 -0
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +1018 -0
- data/test/test_saj.rb +186 -0
- data/test/test_scp.rb +433 -0
- data/test/test_strict.rb +410 -0
- data/test/test_various.rb +741 -0
- data/test/test_wab.rb +307 -0
- data/test/test_writer.rb +380 -0
- data/test/tests.rb +24 -0
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- data/test/zoo.rb +13 -0
- metadata +359 -0
data/pages/JsonGem.md
ADDED
@@ -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.
|
data/pages/Modes.md
ADDED
@@ -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.
|
data/pages/Options.md
ADDED
@@ -0,0 +1,283 @@
|
|
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
|
+
### :safe
|
215
|
+
|
216
|
+
The JSON gem includes the complete JSON in parse errors with no limit
|
217
|
+
on size. To break from the JSON gem behavior for this case set `:safe`
|
218
|
+
to true.
|
219
|
+
|
220
|
+
### :second_precision [Fixnum]
|
221
|
+
|
222
|
+
The number of digits after the decimal when dumping the seconds of time.
|
223
|
+
|
224
|
+
### :space
|
225
|
+
|
226
|
+
String inserted after 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
|
+
### :space_before
|
231
|
+
|
232
|
+
String inserted before the ':' character when dumping a JSON object. The
|
233
|
+
default is an empty string. Primarily intended for json gem
|
234
|
+
compatibility. Using just indent as an integer gives better performance.
|
235
|
+
|
236
|
+
### :symbol_keys [Boolean]
|
237
|
+
|
238
|
+
Use symbols instead of strings for hash keys. :symbolize_names is an alias.
|
239
|
+
|
240
|
+
### :trace
|
241
|
+
|
242
|
+
When true dump and load functions are traced by printing beginning and ending
|
243
|
+
of blocks and of specific calls.
|
244
|
+
|
245
|
+
### :time_format [Symbol]
|
246
|
+
|
247
|
+
The :time_format when dumping.
|
248
|
+
|
249
|
+
- `:unix` time is output as a decimal number in seconds since epoch including fractions of a second.
|
250
|
+
|
251
|
+
- `:unix_zone` similar to the `:unix` format but with the timezone encoded in
|
252
|
+
the exponent of the decimal number of seconds since epoch.
|
253
|
+
|
254
|
+
- `:xmlschema` time is output as a string that follows the XML schema definition.
|
255
|
+
|
256
|
+
- `:ruby` time is output as a string formatted using the Ruby `to_s` conversion.
|
257
|
+
|
258
|
+
### :use_as_json [Boolean]
|
259
|
+
|
260
|
+
Call `as_json()` methods on dump, default is false. The option is ignored in
|
261
|
+
the :compat and :rails mode.
|
262
|
+
|
263
|
+
|
264
|
+
### :use_raw_json [Boolean]
|
265
|
+
|
266
|
+
Call `raw_json()` methods on dump, default is false. The option is
|
267
|
+
accepted in the :compat and :rails mode even though it is not
|
268
|
+
supported by other JSON gems. It provides a means to optimize dump or
|
269
|
+
generate performance. The `raw_json(depth, indent)` method should be
|
270
|
+
called only by Oj. It is not intended for any other use. This is mean
|
271
|
+
to replace the abused `to_json` methods. Calling `Oj.dump` inside the
|
272
|
+
`raw_json` with the object itself when `:use_raw_json` is true will
|
273
|
+
result in an infinite loop.
|
274
|
+
|
275
|
+
### :use_to_hash [Boolean]
|
276
|
+
|
277
|
+
Call `to_hash()` methods on dump, default is false. The option is ignored in
|
278
|
+
the :compat and :rails mode.
|
279
|
+
|
280
|
+
### :use_to_json [Boolean]
|
281
|
+
|
282
|
+
Call `to_json()` methods on dump, default is false. The option is ignored in
|
283
|
+
the :compat and :rails mode.
|