             self = .string(string)
             
         case let number as NSNumber:
-            if number.isBoolean {
-                self = .bool(number.boolValue)
-            } else {
-                self = .number(number.doubleValue)
-            }
-            
-        case _ as NSNull:
+            self = number.isBoolean ? .bool(number.boolValue) : .number(number.doubleValue)
+            
+        case _ as Optional<Any>:
             self = .null
             
         default:
             assert(true, "This location should never be reached")
             self = .invalid
         }
-
-    }
-
+        
+    }
+    
     public var string : String? {
         guard case .string(let value) = self else {
             return nil
         }
         return value
     }
-
+    
     public var integer : Int? {
         guard case .number(let value) = self else {
             return nil
         }
-         return Int(value)
-    }
-
+        return Int(value)
+    }
+    
     public var double : Double? {
         guard case .number(let value) = self else {
             return nil
         }
         return value
     }
-
+    
     public var object : [String: JSON]? {
         guard case .object(let value) = self else {
             return nil
         }
         return value
     }
-
+    
     public var array : [JSON]? {
         guard case .array(let value) = self else {
             return nil
         }
         return value
     }
-
+    
     public var bool : Bool? {
         guard case .bool(let value) = self else {
             return nil
         }
         return value
     }
-
+    
     public subscript(key: String) -> JSON {
         guard case .object(let dict) = self, let value = dict[key] else {
             return .invalid
         }
         return value
     }
-
+    
     public subscript(index: Int) -> JSON {
         guard case .array(let array) = self, array.count > index else {
             return .invalid
         }
         return array[index]
     }
-
+    
     static func parse(jsonData: Data) throws -> JSON {
         do {
             let object = try JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers)

        }
        return prettyPrint(indent, 0)
    }

}

public func ==(lhs: JSON, rhs: JSON) -> Bool {

        
    case (.bool(let lhsValue), .bool(let rhsValue)):
        return lhsValue == rhsValue
        
    case (.string(let lhsValue), .string(let rhsValue)):
        return lhsValue == rhsValue
        
    case (.number(let lhsValue), .number(let rhsValue)):
        return lhsValue == rhsValue
        
    case (.array(let lhsValue), .array(let rhsValue)):
        return lhsValue == rhsValue
        
    case (.object(let lhsValue), .object(let rhsValue)):
        return lhsValue == rhsValue
        
