JSON to Swift
Generate Swift Codable structs with automatic CodingKeys mappings for iOS, iPadOS, and macOS apps.
- Runs in your browser
- Free, no signup
struct Root: Codable {
let id: Int
let name: String
let email: String
let isAdmin: Bool
let roles: [String]
let profile: Profile
enum CodingKeys: String, CodingKey {
case id
case name
case email
case isAdmin = "is_admin"
case roles
case profile
}
}
struct Profile: Codable {
let bio: String
let reputation: Int
}
Your files are processed locally in your browser and are not uploaded to our server.
Building iOS, macOS, watchOS, or server-side Swift applications requires strong models conforming to Apple's Codable protocol. This tool converts any JSON payload into clean Swift structs ready to decode with JSONDecoder.
The generator handles property type mapping (String, Int, Double, Bool), optional types (T?), and array collections ([T]). Whenever a JSON key uses snake_case or is not a valid Swift identifier, the generator creates an enum CodingKeys: String, CodingKey mapping to maintain idiomatic Swift property names.
How to use this tool
- Paste your JSON payload into the editor or click "Load Sample" to try a sample music/media API response.
- Specify your desired root struct name (e.g. TrackResponse or UserData).
- Review the generated Swift Codable structs and CodingKeys in the right-hand panel.
- Click "Copy Code" to copy to your clipboard or "Download .swift" to save a file ready for Xcode.
Native Swift Codable Protocol Conformance
Apple's Codable protocol (Encodable & Decodable) is the standard way to serialize and deserialize data in modern Swift. All generated structs automatically conform to Codable, allowing seamless decoding with JSONDecoder().decode(Root.self, from: data).
Nested JSON objects are extracted into separate, strongly typed Swift structs conforming to Codable, keeping your data layer clean and testable.
Automatic CodingKeys for snake_case and Reserved Words
Swift naming guidelines require camelCase properties (such as "trackId" or "releaseYear"), but backend APIs often return snake_case keys (such as "track_id" or "release_year").
When property names differ from the JSON key, the generator automatically synthesizes an inner enum CodingKeys: String, CodingKey enum with explicit case assignments, so your Swift code stays clean while decoding accurately.
Robust Optional Handling for Missing and Null Values
If a property contains null in your JSON input, the generator declares it as an optional type (e.g., String?, Int?, or [String]?). This prevents decoding crashes when optional fields are omitted by your backend API.
100% In-Browser Swift Generation
Your mobile app payloads and API responses remain completely private. The tool runs locally in your web browser with zero server uploads.
Frequently asked questions
Does the generated Swift code work with Swift 5 and Swift 6?
Yes. The generated structs use standard Codable protocol syntax compatible with Swift 5, Swift 6, SwiftUI, and UIKit.
How does CodingKeys generation work?
Whenever a JSON property is renamed (for instance, converting snake_case "user_name" to "userName"), the generator adds an enum CodingKeys: String, CodingKey block mapping the Swift identifier to the exact JSON key.
Can I download the output as a .swift file?
Yes. Click the "Download .swift" button to download a formatted file that you can drag and drop directly into your Xcode project.
Is my JSON data uploaded or stored anywhere?
No. All processing occurs exclusively in your web browser using JavaScript. No JSON data is ever uploaded or logged.