module JSON

def self.default_options

def self.default_options
  @default_options ||= {:symbolize_keys => false}
end

def self.dump(obj, io=nil, *args)

def self.dump(obj, io=nil, *args)
  begin
    Yajl::Encoder.encode(obj, io)
  rescue Yajl::EncodeError => e
    raise JSON::GeneratorError, e.message
  end
end

def self.generate(obj, opts=nil)

def self.generate(obj, opts=nil)
  opts ||= {}
  options_map = {}
  if opts.has_key?(:indent)
    options_map[:pretty] = true
    options_map[:indent] = opts[:indent]
  end
  Yajl::Encoder.encode(obj, options_map)
rescue Yajl::EncodeError => e
  raise JSON::GeneratorError, e.message
end

def self.load(input, *args)

def self.load(input, *args)
  begin
    Yajl::Parser.parse(input, default_options)
  rescue Yajl::ParseError => e
    raise JSON::ParserError, e.message
  end
end

def self.parse(str, opts=JSON.default_options)

def self.parse(str, opts=JSON.default_options)
  begin
    Yajl::Parser.parse(str, opts)
  rescue Yajl::ParseError => e
    raise JSON::ParserError, e.message
  end
end

def self.pretty_generate(obj, opts={})

def self.pretty_generate(obj, opts={})
  begin
    options_map = {}
    options_map[:pretty] = true
    options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
    Yajl::Encoder.encode(obj, options_map)
  rescue Yajl::EncodeError => e
    raise JSON::GeneratorError, e.message
  end
end