Add a 'process_nested' option to fire a callback on nested objects #50

Open
wants to merge 2 commits into from

3 participants

@hoxworth

A limitation I have run into in the past in using the yajl-ruby Gem for parsing large JSON documents is the case where I need to parse a very large array of objects but would like to have a callback fired on each object as opposed to the on_parse_complete callback at the end. I had been using a hacked-together patch personally for a while, but figured it made sense to push this to the main project.

This patch adds a process_nested option to theYajl::Parser.new call that will call a on_parse_nested (if set) callback when every object / array is parsed from the JSON along with the depth the object was parsed at. An additional option to the Yajl::Parser.new call, nested_depth, may be called to declare at what maximum depth the callback will be fired; 0, the default, will fire the callback on every object.

The on_parse_nested Proc receives two arguments, obj and depth. obj is the same object received by the on_parse_complete callback, and depth is the depth at which the nested object was parsed.

Let me know if you have any questions, or if you feel this doesn't make sense for the yajl-ruby project.

@brianmario
Owner

We probably don't need the process_nested boolean here if we can just infer that they want to use the feature based on if the nested_depth key exists in the options hash?

@avsej avsej added a commit to avsej/yajl-ruby that referenced this pull request Dec 8, 2011
@avsej avsej Replace 'process_nested' option with test of 'on_parse_nested' (issue #…
…50)

It uses the fact of availability 'on_parse_nested' callback instead of
'process_nested' option. This patch also remove trailing spaces introduces
by hoxworth
8ca9f3e
@avsej

HI all, @brianmario maybe my patch will help to accept this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment