Method: Oj.strict_load

Defined in:
ext/oj/oj.c

.strict_load(json, options) { ... } ⇒ Object

Parses a JSON document String into an Hash, Array, String, Fixnum, Float, true, false, or nil. It parses using a mode that is strict in that it maps each primitive JSON type to a similar Ruby type. The :create_id is not honored in this mode. Note that a Ruby Hash is used to represent the JSON Object type. These two are not the same since the JSON Object type can have repeating entries with the same key and Ruby Hash can not.

When used with a document that has multiple JSON elements the block, if any, will be yielded to. If no block then the last element read will be returned.

Raises an exception if the JSON is malformed or the classes specified are not valid. If the input is not a valid JSON document (an empty string is not a valid JSON document) an exception is raised.

A block can be provided with a single argument. That argument will be the parsed JSON document. This is useful when parsing a string that includes multiple JSON documents. The block can take up to 3 arguments, the parsed object, the position in the string or stream of the start of the JSON for that object, and the length of the JSON for that object plus trailing whitespace.

  • json [String|IO] JSON String or an Object that responds to read().

  • options [Hash] load options (same as default_options).

  • obj [Hash|Array|String|Fixnum|Float|Boolean|nil] parsed object.

  • start [_optional, Integer] start position of parsed JSON for obj.

  • len [_optional, Integer] length of parsed JSON for obj.

Returns [Hash|Array|String|Fixnum|Float|Boolean|nil]

Yields:

[View source]

1538
# File 'ext/oj/oj.c', line 1538

extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);