Method: Oj.default_options=

Defined in:
ext/oj/oj.c

.default_options=(opts) ⇒ Object

Sets the default options for load and dump.

  • opts [Hash] options to change

    • :indent [Fixnum|String|nil] number of spaces to indent each element in a JSON document or the String to use for indentation.

    • :circular [Boolean|nil] support circular references while dumping.

    • :auto_define [Boolean|nil] automatically define classes if they do not exist.

    • :symbol_keys [Boolean|nil] convert hash keys to symbols.

    • :class_cache [Boolean|nil] cache classes for faster parsing.

    • :escape [:newline|:json|:xss_safe|:ascii|unicode_xss|nil] mode encodes all high-bit characters as escaped sequences if :ascii, :json is standand UTF-8 JSON encoding, :newline is the same as :json but newlines are not escaped, :unicode_xss allows unicode but escapes &, <, and >, and any u20xx characters along with some others, and :xss_safe escapes &, <, and >, and some others.

    • :bigdecimal_as_decimal [Boolean|nil] dump BigDecimal as a decimal number or as a String.

    • :bigdecimal_load [:bigdecimal|:float|:auto|nil] load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.

    • :compat_bigdecimal [true|false] load decimals as BigDecimal instead of as a Float in compat mode.

    • :mode [:object|:strict|:compat|:null|:custom|:rails|:wab] load and dump mode to use for JSON :strict raises an exception when a non-supported Object is encountered. :compat attempts to extract variable values from an Object using to_json() or to_hash() then it walks the Object’s variables if neither is found. The :object mode ignores to_hash() and to_json() methods and encodes variables using code internal to the Oj gem. The :null mode ignores non-supported Objects and replaces them with a null. The :custom mode honors all dump options. The :rails more mimics rails and Active behavior.

    • :time_format [:unix|:xmlschema|:ruby] time format when dumping in :compat mode :unix decimal number denoting the number of seconds since 1/1/1970, :unix_zone decimal number denoting the number of seconds since 1/1/1970 plus the utc_offset in the exponent, :xmlschema date-time format taken from XML Schema as a String, :ruby Time.to_s formatted String.

    • :create_id [String|nil] create id for json compatible object encoding

    • :create_additions [Boolean|nil] if true allow creation of instances using create_id on load.

    • :second_precision [Fixnum|nil] number of digits after the decimal when dumping the seconds portion of time.

    • :float_format [String] the C printf format string for printing floats. Default follows the float_precision and will be changed if float_precision is changed. The string can be no more than 6 bytes.

    • :float_precision [Fixnum|nil] number of digits of precision when dumping floats, 0 indicates use Ruby.

    • :use_to_json [Boolean|nil] call to_json() methods on dump, default is false.

    • :use_as_json [Boolean|nil] call as_json() methods on dump, default is false.

    • :use_to_hash [Boolean|nil] call to_hash() methods on dump, default is false.

    • :use_raw_json [Boolean|nil] call raw_json() methods on dump, default is false.

    • :nilnil [Boolean|nil] if true a nil input to load will return nil and not raise an Exception.

    • :allow_gc [Boolean|nil] allow or prohibit GC during parsing, default is true (allow).

    • :quirks_mode [Boolean|nil] allow single JSON values instead of documents, default is true (allow).

    • :allow_invalid_unicode [Boolean|nil] allow invalid unicode, default is false (don’t allow).

    • :allow_nan [Boolean|nil] allow Nan, Infinity, and -Infinity, default is true (allow).

    • :space [String|nil] String to use for the space after the colon in JSON object fields.

    • :space_before [String|nil] String to use before the colon separator in JSON object fields.

    • :object_nl [String|nil] String to use after a JSON object field value.

    • :array_nl [String|nil] String to use after a JSON array value

    • :nan [:null|:huge|:word|:raise] how to dump Infinity and NaN in null, strict, and compat mode. :null places a null, :huge places a huge number, :word places Infinity or NaN, :raise raises and exception, :auto uses default for each mode.

    • :hash_class [Class|nil] Class to use instead of Hash on load, :object_class can also be used.

    • :array_class [Class|nil] Class to use instead of Array on load.

    • :omit_nil [true|false] if true Hash and Object attributes with nil values are omitted.

    • :ignore [nil|Array] either nil or an Array of classes to ignore when dumping

    • :ignore_under [Boolean] if true then attributes that start with _ are ignored when dumping in object or custom mode.

    • :cache_keys [Boolean] if true then hash keys are cached

    • :cache_str [Fixnum] maximum string value length to cache (strings less than this are cached)

    • :integer_range [Range] Dump integers outside range as strings.

    • :trace [Boolean] turn trace on or off.

    • :safe [Boolean] turn safe mimic on or off.

[View source]

569
570
571
572
573
574
# File 'ext/oj/oj.c', line 569

static VALUE set_def_opts(VALUE self, VALUE opts) {
    Check_Type(opts, T_HASH);
    oj_parse_options(opts, &oj_default_options);

    return Qnil;
}