 extension Json {
     
     public var data: Data? {
-        if let value = self.value, JSONSerialization.isValidJSONObject(value) {
-            return try? JSONSerialization.data(withJSONObject: value, options: [])
+        if JSONSerialization.isValidJSONObject(self.value) {
+            return try? JSONSerialization.data(withJSONObject: self.value, options: [])
         }
         return nil
     }


public struct Json {
    
    fileprivate let value: Any?
    
    fileprivate init(value: Any?) {
        self.value = value
    }
    
    fileprivate static func unwrap(_ value: Any) -> Any? {
        if let json = value as? Json {
            return json.value
        }

            return nil
        }
        set {
            self = Json(value: newValue?.map { $0.value })
        }
    }
    public var dictionary: [String: Json]? {
        get {
            if let elements = self.value as? [String: Any] {
                var dictionary = [String: Json](minimumCapacity: elements.count)
                for (key, value) in elements {
                    dictionary[key] = Json(value: value)
                }
                return dictionary
            }
            return nil
        }
        set {
            if let elements = newValue {
                var dictionary = [String: Any](minimumCapacity: elements.count)
                for (key, value) in elements {
                    dictionary[key] = value.value
                }
                self = Json(value: dictionary)
            } else {
                self = nil
            }
        }
    }
}

