Skip to content

Instantly share code, notes, and snippets.

@stevej
Created October 6, 2008 17:30
Show Gist options
  • Save stevej/15083 to your computer and use it in GitHub Desktop.
Save stevej/15083 to your computer and use it in GitHub Desktop.
Validates a directory full of JSON files.
#!/usr/bin/ruby
require 'rubygems'
require 'json'
dir = ARGV.shift
def readfile(filename)
return '[]' if File.directory?(filename)
body = ''
file = File::open(filename)
file.each do |line|
body << line
end
file.close
body
end
Dir.entries(dir).each do |filename|
puts "parsing: #{filename}"
JSON.parse(readfile(filename))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment