         get {
             switch self {
             case .Object(let o):
-                return o[key] ?? .Error("subscript \"\(key)\" is nonexistent")
+                return o[key] ?? .Error(.keyNonexistent(key))
             default:
-                return .Error("\"\(self)\" is not an object")
+                return .Error(.typeMismatch(self.type))
             }
         }
         set {

import Foundation

public enum JSON:Equatable {
    public typealias Key        = String
    public typealias Value      = JSON
    public typealias Index      = Int
    public typealias ErrorType  = String
    case Error(ErrorType)
    case Null
    case Bool(Bool)
    case Number(Double)

        get {
            switch self {
            case .Array(let a):
                guard idx < a.count else { return .Error(.indexOutOfRange(idx)) }
                return a[idx]
            default:
                return .Error(.typeMismatch(self.type))
            }
        }
        set {
