Last active
January 7, 2016 02:45
-
-
Save arangamani/5407512 to your computer and use it in GitHub Desktop.
A JSON lint tool using Ruby and "json" Rubygem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your rescue block masks the json error location. Use https://github.com/dougbarth/jsonlint instead.