JSON to Swift Converter

Generate Swift structs from JSON. Paste your JSON:

Loading...
Loading...

Generate Swift Codable Structs

This tool converts JSON to Swift structs conforming to the Codable protocol. It automatically generates CodingKeys for property name mapping.

Example Output

struct User: Codable {
    let id: Int
    let userName: String
    let isActive: Bool

    enum CodingKeys: String, CodingKey {
        case id
        case userName = "user_name"
        case isActive = "is_active"
    }
}

Type Mapping

JSONSwift
stringString
integerInt
decimalDouble
booleanBool
nullString?
array[T]
objectNested struct

Using Generated Code

let jsonData = """
{"id": 1, "user_name": "john"}
""".data(using: .utf8)!

let decoder = JSONDecoder()
let user = try decoder.decode(User.self, from: jsonData)
print(user.userName) // "john"

Related Tools