 import Foundation
 
 public enum JSON:Equatable {
+    public enum JSONError : Equatable {
+        case notAJSONObject
+        case typeMismatch(JSON.ContentType)
+        case indexOutOfRange(JSON.Index)
+        case keyNonexistent(JSON.Key)
+        case nsError(NSError)
+    }
     public typealias Key        = String
     public typealias Value      = JSON
     public typealias Index      = Int
-    public typealias ErrorType  = String
-    case Error(ErrorType)
+    case Error(JSONError)
     case Null
     case Bool(Bool)
     case Number(Double)

        }
    }
    public var isNull:Bool          { return type == .null }
    public var error:ErrorType?     { switch self { case .Error(let v): return v default: return nil } }
    public var bool:Bool? {
        get { switch self { case .Bool(let v):  return v default: return nil } }
        set { self = .Bool(newValue!) }

        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 {
