JSON to Swift Codable
Convert JSON into Swift Codable structs for iOS apps.
Turn representative JSON into Swift models
Infer nested types and generate a copy-ready Codable struct starting from one realistic payload.
Swift
language
Root
root type
12 lines
output
Representative JSON
129 charactersSwift output
Generated locallyTypes are inferred only from this sample. Null values become optional; verify optionality, coding keys and numeric ranges against the complete API contract.
About the JSON to Swift Codable
iOS and macOS apps decode JSON from APIs into Swift models. Writing those Codable structs by hand is tedious and error-prone.
This tool reads a JSON sample and generates Swift structs conforming to Codable, inferring types for strings, numbers, booleans, arrays and nested objects.
Everything runs in your browser, so your JSON never leaves your device.
Key features
- Generates Codable structs from JSON
- Infers Int, Double, Bool, String, arrays and nested types
- Custom root type name
- Local, private conversion
How to use
- 1Paste a JSON sample.
- 2Set the root type name if you like.
- 3Copy the generated Swift structs.
Examples
{ "id": 1, "name": "Ada" }struct Root: Codable { let id: Int; let name: String }Numbers become Int or Double and strings become String, all inside a Codable struct.
Frequently asked questions
- Does it conform to Codable?
- Yes. Every generated struct conforms to Codable, so you can decode and encode it with JSONDecoder and JSONEncoder out of the box.
- How are null values handled?
- A null becomes an optional String? because the real type cannot be inferred from null alone. Adjust it to the correct optional type for your model.
- Can it handle nested objects and arrays?
- Yes. Nested objects become their own structs and arrays become typed arrays based on the first element.
Continue your workflow
Open a related tool to prepare your files or refine the finished result.
- Featured toolDeveloper ToolsJSON to Kotlin Data Class
Convert JSON into Kotlin data classes for Android apps.
Open tool - ConvertersJSON to TypeScript Converter
Generate TypeScript interfaces from a JSON sample.
Open tool - Featured toolDeveloper ToolsColor to Mobile Code
Convert a hex colour to SwiftUI, UIKit, Jetpack Compose and Android XML code.
Open tool
