Class Yajl::Parser
In: lib/yajl.rb
ext/yajl_ext.c
Parent: Object

This class contains methods for parsing JSON directly from an IO object. The only basic requirment currently is that the IO object respond to read(len) and eof? The IO is parsed until a complete JSON object has been read and a ruby object will be returned.

Methods

<<   new   new   on_parse_complete=   parse   parse   parse_chunk  

Public Class methods

:symbolize_keys will turn hash keys into Ruby symbols, defaults to false.

:allow_comments will turn on/off the check for comments inside the JSON stream, defaults to true.

:check_utf8 will validate UTF8 characters found in the JSON stream, defaults to true.

:symbolize_keys will turn hash keys into Ruby symbols, defaults to false.

:allow_comments will turn on/off the check for comments inside the JSON stream, defaults to true.

:check_utf8 will validate UTF8 characters found in the JSON stream, defaults to true.

A helper method for parse-and-forget use-cases

io is the stream to parse JSON from

The options hash allows you to set two parsing options - :allow_comments and :check_utf8

:allow_comments accepts a boolean will enable/disable checks for in-line comments in the JSON stream

:check_utf8 accepts a boolean will enable/disable UTF8 validation for the JSON stream

Public Instance methods

Document-method: parse_chunk

string_chunk can be a partial or full JSON string to push on the parser.

This method will throw an exception if the on_parse_complete callback hasn‘t been assigned yet. The on_parse_complete callback assignment is required so the user can handle objects that have been parsed off the stream as they‘re found.

This callback setter allows you to pass a Proc/lambda or any other object that responds to call.

It will pass a single parameter, the ruby object built from the last parsed JSON object

input can either be a string or an IO to parse JSON from

buffer_size is the size of chunk that will be parsed off the input (if it‘s an IO) for each loop of the parsing process. 8092 is a good balance between the different types of streams (off disk, off a socket, etc…), but this option is here so the caller can better tune their parsing depending on the type of stream being passed. A larger read buffer will perform better for files off disk, where as a smaller size may be more efficient for reading off of a socket directly.

If a block was passed, it‘s called when an object has been parsed off the stream. This is especially usefull when parsing a stream of multiple JSON objects.

NOTE: you can optionally assign the on_parse_complete callback, and it will be called the same way the optional block is for this method.

string_chunk can be a partial or full JSON string to push on the parser.

This method will throw an exception if the on_parse_complete callback hasn‘t been assigned yet. The on_parse_complete callback assignment is required so the user can handle objects that have been parsed off the stream as they‘re found.

[Validate]