 }
 
 extension Array {
-  public static func decodeJson(decodeElement: AnyObject throws -> Element, _ json: AnyObject) throws -> [Element] {
-    guard let arr = json as? [AnyObject] else {
-      throw JsonDecodeError.WrongType(rawValue: json, expectedType: "Array")
-    }
-
-    var errors: [Int: JsonDecodeError] = [:]
-    var result: [Element] = []
-
-    for (index, element) in arr.enumerate() {
-      do {
-        result.append(try decodeElement(element))
-      }
-      catch let error as JsonDecodeError {
-        errors[index] = error
-      }
-    }
-
-    if errors.count > 0 {
-      throw JsonDecodeError.ArrayElementErrors(errors)
-    }
-
-    return result
+  public static func decodeJson(decodeElement: AnyObject throws -> Element) -> AnyObject throws -> [Element] {
+    return { json in
+      guard let arr = json as? [AnyObject] else {
+        throw JsonDecodeError.WrongType(rawValue: json, expectedType: "Array")
+      }
+
+      var errors: [Int: JsonDecodeError] = [:]
+      var result: [Element] = []
+
+      for (index, element) in arr.enumerate() {
+        do {
+          result.append(try decodeElement(element))
+        }
+        catch let error as JsonDecodeError {
+          errors[index] = error
+        }
+      }
+
+      if errors.count > 0 {
+        throw JsonDecodeError.ArrayElementErrors(errors)
+      }
+
+      return result
+    }
   }
 
   public func encodeJson(encodeJsonElement: Element -> AnyObject) -> [AnyObject] {

  case StructErrors(type: String, errors: [String: JsonDecodeError])
}

// Decode function for JsonObject.
// Would be nicer as an extension method.
public func JsonObject_decodeJson(json: AnyObject) throws -> JsonObject {
  guard let result = json as? JsonObject else {
    throw JsonDecodeError.WrongType(rawValue: json, expectedType: "JsonObject")
  }

  return result
}

extension String {

}

extension Dictionary {
  public static func decodeJson(decodeKey: AnyObject throws -> Key, _ decodeValue: AnyObject throws -> Value) -> AnyObject throws -> [Key: Value] {
    return { json in
      guard let dict = json as? [Key: AnyObject] else {
        throw JsonDecodeError.WrongType(rawValue: json, expectedType: "Dictionary")
      }

      var errors: [String: JsonDecodeError] = [:]
      var result: [Key: Value] = [:]

      for (key, val) in dict {
        do {
          result[key] = try decodeValue(val)
        }
        catch let error as JsonDecodeError {
          errors["\(key)"] = error
        }
      }

      if errors.count > 0 {
        throw JsonDecodeError.DictionaryErrors(errors)
      }

      return result
    }
  }

  public func encodeJson(encodeJsonKey: Key -> String, _ encodeJsonValue: Value -> AnyObject) -> [String: AnyObject] {
