9 opts = go 'slhi:', args = ARGV.dup
10 if opts['h'] || opts['l'] && opts['s']
12 Usage: #{File.basename($0)} [OPTION] [FILE]
14 If FILE is skipped, this scripts waits for input from STDIN. Otherwise
15 FILE is opened, read, and used as input for the prettifier.
18 -s to output the shortest possible JSON (precludes -l)
19 -l to output a longer, better formatted JSON (precludes -s)
20 -i EXT prettifies FILE in place, saving a backup to FILE.EXT
26 json_opts = { :max_nesting => false, :create_additions => false }
29 if filename = args.first or filename == '-'
35 json = JSON.parse document, json_opts
38 JSON.fast_generate json, json_opts
40 JSON.pretty_generate json, json_opts
43 if opts['i'] && filename
44 cp filename, "#{filename}.#{opts['i']}"
45 File.open(filename, 'w') { |f| f.puts output }