Add a 'process_nested' option to fire a callback on nested objects #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_completecallback 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_nestedoption to theYajl::Parser.newcall that will call aon_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 theYajl::Parser.newcall,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_nestedProc receives two arguments,objanddepth.objis the same object received by theon_parse_completecallback, anddepthis 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.