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
| JSON | Swift |
|---|---|
| string | String |
| integer | Int |
| decimal | Double |
| boolean | Bool |
| null | String? |
| array | [T] |
| object | Nested 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
- JSON to Kotlin — For Android development
- JSON to TypeScript — For web apps
- JSON Validator — Validate JSON first