Skip to content

Instantly share code, notes, and snippets.

@thisismydesign
Created May 19, 2017 15:55
Show Gist options
  • Save thisismydesign/66a686b3fe80f2cb8a2a453ac1ffd3e4 to your computer and use it in GitHub Desktop.
Save thisismydesign/66a686b3fe80f2cb8a2a453ac1ffd3e4 to your computer and use it in GitHub Desktop.
How to write a JSON srteamer
@aggregator # what to yield
@current_nesting_level # when to yield
@parser.start_object do
@current_nesting_level += 1
end
@parser.end_object do
if yield_object?(yield_nesting_level)
yield @aggregator[@current_nesting_level].clone
@aggregator = {}
end
@current_nesting_level -= 1
end
@parser.key do
# build @agrregator
end
@parser.value do
# build @agrregator
end
def yield_object?(yield_nesting_level)
@current_nesting_level.eql? yield_nesting_level
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment