public
Last active

Parses a JSON file containing multiple objects that are not contained in a single object.

  • Download Gist
parse_json_multi_records.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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."

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.