summary refs log tree commit diff
path: root/bin/sson
blob: 2a0f46cdbc38b5a1760e3834ed163fcd5cf2d7db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby

$: << File.dirname(File.realpath(__FILE__)) + "/../lib"

require 'sson'

raw = false
if ARGV.first == "-r"
  ARGV.shift
  raw = true
end

input = ARGF.read

begin
  case input[0]
  when "{", "[", '"'
    if raw
      puts SSON.generate(JSON.parse(input))
    else
      puts SSON.pretty_generate(JSON.parse(input))
    end
  else
    if raw
      puts JSON.generate(SSON.parse(input))
    else
      puts JSON.pretty_generate(SSON.parse(input))
    end
  end
rescue SSON::SSONError, JSON::JSONError => e
  abort "error: " + e.message
end