JSON to Swift Codable
Generate Swift structs conforming to the Codable protocol from JSON data. Supports CodingKeys for snake_case mapping and Identifiable conformance.
Features
🍎 Codable Protocol
- Encodable & Decodable
- Nested struct generation
- Proper Swift type mapping
- Foundation import included
🔑 CodingKeys Support
- Auto snake_case to camelCase
- CodingKeys enum generated
- Maps JSON keys correctly
- Optional key customization
⚡ Smart Type Detection
- Int vs Double inference
- Bool, String, optional types
- Array type [T] generation
- Identifiable conformance option
Swift Codable Guide
Swift Codable Protocol
Codable is Swift's type-safe serialization protocol. It combines Encodable and Decodable, enabling you to convert between Swift types and JSON with minimal code.
import Foundation
struct User: Codable {
let id: Int
let name: String
let isActive: Bool
enum CodingKeys: String, CodingKey {
case id
case name
case isActive = "is_active"
}
}