Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
Last active December 19, 2015 09:09
Show Gist options
  • Save keithrbennett/5930475 to your computer and use it in GitHub Desktop.
Save keithrbennett/5930475 to your computer and use it in GitHub Desktop.
Parses a JSON file containing multiple objects that are not contained in a single object.
require 'yajl'
def parse(json_filespec)
json_file = File.new(json_filespec, 'r')
parser = Yajl::Parser.new
records = []
parser.parse(json_file) do |x|
records << x
end
records
end
all_records_in_file = parse 'test.json'
puts "Found #{all_records_in_file.size} records."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment