     }
 
     public var dictionary: [String: JSON]? {
-        return (object as? [String: AnyObject])?.map({ JSON(object: $0) })
+        let block: ([String: JSON], (String, AnyObject)) -> [String: JSON] = { dictionary, element in
+            switch JSON(object: element.1) {
+            case .Some(let JSON):
+                var mutableDictionary = dictionary
+                mutableDictionary[element.0] = JSON
+                return mutableDictionary
+            case .None:
+                return dictionary
+            }
+        }
+        return (object as? [String: AnyObject]).map({ reduce($0, [String: JSON](), block) })
     }
 
     public var array: [JSON]? {
-        return (object as? [AnyObject])?.map({ JSON(object: $0) })
+        let block: ([JSON], AnyObject) -> [JSON] = { array, element in
+            switch JSON(object: element) {
+            case .Some(let JSON):
+                return array + CollectionOfOne(JSON)
+            case .None:
+                return array
+            }
+        }
+        return (object as? [AnyObject])?.reduce([JSON](), combine: block)
     }
 
     public var int: Int? {

    }

    public func decodeArray<T: JSONDecodable>(type: T.Type) -> [T]? {
        return array?.reduce([T](), combine: { array, element in
            switch T.decode(element) {
            case .Some(let object):
                return array + CollectionOfOne(object)
            case .None:
                return array
            }
        })
    }

    public func decodeArray<T>(transform: JSON -> T?) -> [T]? {
        return array?.reduce([T](), combine: { array, element in
            switch transform(element) {
            case .Some(let object):
                return array + CollectionOfOne(object)
            case .None:
                return array
            }
        })
    }
}

//  Copyright (c) 2015 Hodinkee. All rights reserved.
//

import Foundation

public protocol JSONDecodable {
    static func decode(JSON: Alexander.JSON) -> Self?
}

public struct JSON {
    public var object: AnyObject

    public init?(object: AnyObject) {
        if NSJSONSerialization.isValidJSONObject(object) {
            self.object = object
        }
        return nil
    }

    public subscript(index: Int) -> JSON? {
        let array = object as? [AnyObject]
        return (array?[index]).flatMap({ JSON(object: $0) })
    }

    public subscript(key: String) -> JSON? {
        let dictionary = object as? [String: AnyObject]
        return (dictionary?[key]).flatMap({ JSON(object: $0) })
    }

    public var string: String? {
