FREE · DEVELOPER TOOLS
JSON to Swift Codable.
Turn a JSON sample into Swift Codable structs with CodingKeys for snake_case keys, optionals and nested types.
Loading the calculator…
Steps to use JSON to Swift Codable
Paste a JSON object or an array of objects and name the root type. Copy or download Models.swift.
How JSON to Swift Codable processes your input
Integers map to Int, decimals to Double, arrays to [T]; optional or null fields become optionals. A small JSONValue enum is added when a field’s type varies.
JSON to Swift Codable: worked example
user_name becomes let userName: String with case userName = "user_name" in CodingKeys.
Generate Swift Codable structs from JSON
- Paste a JSON object, or an array of objects, from an API response or a sample file.
- Name the root type.
- Copy the code or download Models.swift, then decode with JSONDecoder.
Example: the key user_name becomes let userName: String, with case userName = "user_name" in the CodingKeys enum, so your Swift code stays in camelCase.
How types are mapped
- Integers map to Int, decimals to Double and arrays to [T]. Nested objects become their own structs.
- Fields missing from some items, or null in the sample, become optionals.
- When a field’s type varies, a small JSONValue enum is added so decoding never fails.
- Types come from the sample only, so include complete examples. Everything runs in your browser. For Android, see JSON to Kotlin; to check the JSON first, use the JSON formatter.
Questions about JSON to Swift Codable
Do I need CodingKeys?
Only when JSON keys differ from Swift names, such as snake_case keys. The tool adds them automatically in that case.
Why is a property optional?
Because it was missing or null in at least one item of the sample. Make it non-optional if your API always sends it.
Is my JSON uploaded?
No. The structs are generated in your browser.
Is JSON to Swift Codable free, and do I need an account?
Yes. This tool is free to use in your browser without an account. Processing takes place on your device.
What are the limits and what should I check?
Types are inferred from the sample only. Everything is calculated in your browser; nothing you type is uploaded. Review the result before using it in your work.
Is my input sent to a server?
Your input is processed in your browser and is not uploaded by this tool. Files and pasted text are cleared when the page is refreshed. Normal website requests are still required to load the page and its libraries. Read the privacy explanation.