Expected to decode Int but found a number instead

For these kinds of issues, check and make sure that the response and the type of response given in the struct are the same. Here it seems your response is not correct. The status may true or false

{
    code: 406,
    message: "Email Address already Exist.",
    status: 0
}

If the status is true, change your struct as,

struct Registration: Codable {
    var code: Int
    var status: Bool
    var message: String
}

if the status is 0, change the var status: Bool to var status: Int, in the above struct.


The error message is very misleading. This happens when the JSON contains a boolean value, and the struct has an Int property for the corresponding key.

Most likely your JSON actually looks like this:

{
    "code": 406,
    "message": "Email Address already Exist.",
    "status": false
}

and accordingly, your struct should be

struct Registration: Codable {
    let code: Int
    let status: Bool
}

if let registration = try? JSONDecoder().decode(Registration.self, from: data) {
    print(registration.code) // 406
    print(registration.status) // false
}