Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hoxworth
Copy link

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
Copy link
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 added a commit to avsej/yajl-ruby that referenced this pull request Dec 8, 2011
…rianmario#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
@avsej
Copy link
Contributor

avsej commented Dec 8, 2011

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants