     public func toJSON() -> JSON {
         var result = JSON([
             <%_ propertyInfos.filter((info) => !info.optional).forEach(function(info) { _%>
-                "<%- info.name %>": JSON(<%- info.name %>),
+            "<%- info.name %>": JSON(<%- info.name %>),
             <%_ }); _%>
         ])
         <%_ propertyInfos.filter((info) => info.optional).forEach(function(info) { _%>
-            if let <%- info.name %> = <%- info.name %> {
-                result["<%- info.name %>"] = JSON(<%- info.name %>)
-            }
+        if let <%- info.name %> = <%- info.name %> {
+            result["<%- info.name %>"] = JSON(<%- info.name %>)
+        }
         <%_ }); _%>
+
         return result
     }
 }


    public func updatingWith(json: JSON) throws -> <%- model.classname %> {
        <%_ propertyInfos.forEach(function(info) { _%>
            if json["<%- info.name %>"].exists() &&
               json["<%- info.name %>"].type != .<%- info.swiftyJSONType %> {
                throw ModelError.propertyTypeMismatch(name: "<%- info.name %>", type: "<%- info.jsType %>", value: json["<%- info.name %>"].description, valueType: String(describing: json["<%- info.name %>"].type))
            }
            <%_ if (info.jsType === 'number') { _%>
                let <%- info.name %> = json["<%- info.name %>"].number.map { Double($0) } ?? self.<%- info.name %>
            <%_ } else { _%>
                let <%- info.name %> = json["<%- info.name %>"].<%- info.swiftyJSONProperty %> ?? self.<%- info.name %>
            <%_ } _%>
        <%_ }); _%>
        return <%- model.classname %>(<%- propertyInfos.map((info) => `${info.name}: ${info.name}`).join(', ') %>)
    }

                <%_ var swiftDefaultLiteral = helpers.convertJSDefaultValueToSwift(model.properties[info.name].default); _%>
                <%_ defaultValueClause = ' ?? ' + swiftDefaultLiteral; _%>
            <%_ } _%>
        if json["<%- info.name %>"].exists() &&
           json["<%- info.name %>"].type != .<%- info.swiftyJSONType %> {
            throw ModelError.propertyTypeMismatch(name: "<%- info.name %>", type: "<%- info.jsType %>", value: json["<%- info.name %>"].description, valueType: String(describing: json["<%- info.name %>"].type))
        }
            <%_ if (info.jsType === 'number') { _%>
        self.<%- info.name %> = json["<%- info.name %>"].number.map { Double($0) }<%- defaultValueClause %>
            <%_ } else { _%>
        self.<%- info.name %> = json["<%- info.name %>"].<%- info.swiftyJSONProperty %><%- defaultValueClause %>
            <%_ } _%>
        <%_ }); _%>

