Method: Oj.safe_load

Defined in:
ext/oj/oj.c

.safe_load(doc) ⇒ Object

Loads a JSON document in strict mode with :auto_define and :symbol_keys turned off. This function should be safe to use with JSON received on an unprotected public interface.

  • doc [String_|IO] JSON String or IO to load.

Returns [Hash|Array|String|Fixnum|Bignum|BigDecimal|nil|True|False]



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
# File 'ext/oj/oj.c', line 1225

static VALUE safe_load(VALUE self, VALUE doc) {
    struct _parseInfo pi;
    VALUE             args[1];

    parse_info_init(&pi);
    pi.err_class           = Qnil;
    pi.max_depth           = 0;
    pi.options             = oj_default_options;
    pi.options.auto_define = No;
    pi.options.sym_key     = No;
    pi.options.mode        = StrictMode;
    oj_set_strict_callbacks(&pi);
    *args = doc;

    return oj_pi_parse(1, args, &pi, 0, 0, 1);
}