# File lib/json/common.rb, line 231
  def pretty_generate(obj, opts = nil)
    state = JSON.state.new(
      :indent     => '  ',
      :space      => ' ',
      :object_nl  => "\n",
      :array_nl   => "\n",
      :check_circular => true
    )
    if opts
      if opts.respond_to? :to_hash
        opts = opts.to_hash
      elsif opts.respond_to? :to_h
        opts = opts.to_h
      else
        raise TypeError, "can't convert #{opts.class} into Hash"
      end
      state.configure(opts)
    end
    result = obj.to_json(state)
    if result !~ /\A\s*(?:\[.*\]|\{.*\})\s*\Z/m
      raise GeneratorError, "only generation of JSON objects or arrays allowed"
    end
    result
  end