Skip to content

Instantly share code, notes, and snippets.

@arangamani
Last active January 7, 2016 02:45
Show Gist options
  • Save arangamani/5407512 to your computer and use it in GitHub Desktop.
Save arangamani/5407512 to your computer and use it in GitHub Desktop.
A JSON lint tool using Ruby and "json" Rubygem
#!/usr/bin/env ruby
require "rubygems"
require "json"
if ARGV.size < 1
puts "Please provide a JSON file"
exit 1
end
file_name = ARGV.shift
begin
JSON.load(File.read(file_name))
puts "Syntax OK"
exit 0
rescue JSON::ParserError
puts "Syntax Error!"
exit 1
end
@saurabh-hirani
Copy link

Your rescue block masks the json error location. Use https://github.com/dougbarth/jsonlint instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment