Method: Oj.object_load

Defined in:
ext/oj/oj.c

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

Parses a JSON document String into an Object, Hash, Array, String, Fixnum, Float, true, false, or nil. In the :object mode the JSON should have been generated by Oj.dump(). The parser will reconstitute the original marshalled or dumped Object. The :auto_define and :circular options have meaning with this parsing mode.

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:



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

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