-
-
Save vkhatri/9340641 to your computer and use it in GitHub Desktop.
dummy json syntax check wrapper
This file contains 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' | |
require 'optparse' | |
o = {} | |
OptionParser.new do |opts| | |
opts.on("-h", "--help", "help") { |h| o[:help] = true } | |
opts.on("-v", "--verbose", "verbose") { |h| o[:verbose] = true } | |
end.parse! | |
puts "usage: j file.json file.json .. file.json [-v prints json file]" if o[:help] | |
if ARGV.length == 0 | |
puts "\nmissing file, usage: j <file.json>" | |
exit 0 | |
end | |
ARGV.each { |file| | |
if file | |
unless File.exists?(file) | |
puts "\nfile=#{file}, file does not exists" | |
exit 0 | |
end | |
end | |
begin | |
raw = File.read(file) | |
json = JSON.parse(raw) | |
json_pretty = JSON.pretty_generate(json) | |
if o[:verbose] | |
puts json_pretty | |
puts "\n\n#{file} Parsed: Ok\n" | |
else | |
puts "\n#{file} Parsed: Ok\n" | |
end | |
rescue => error | |
puts "\n#{file}, Parsing Failed" | |
puts error.class | |
puts error.message | |
puts error.backtrace | |
end | |
puts "-----" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment