JSON to Swift Codable — Free Online
JSON to Swift Codable generator — produces Codable structs with CodingKeys for non-camelCase keys. Built for iOS, macOS, and visionOS workflows.
PDFFlare's JSON to Swift Codable generator creates one struct per unique object shape, CodingKeys enums whenever a JSON key needs remapping, sensible type inference (Int, Double, Bool, [T]). Built for iOS, macOS, watchOS, and visionOS workflows.
Building on Android too? JSON to Kotlin. Web? JSON to TypeScript.
How to Generate Swift Codable Structs from JSON
Paste a JSON sample
An API response, a payload from a Swift Playground request, or any JSON you want typed.
Click Convert to Swift
PDFFlare emits one Codable struct per unique object shape, with a CodingKeys enum whenever a JSON key uses snake_case or punctuation that doesn't fit Swift's identifier rules.
Drop into your Xcode project
Paste the structs into a .swift file. JSONDecoder().decode(Root.self, from: data) gives you typed values straight from URLSession.
When Do You Need JSON to Swift?
iOS API clients: You hit a REST endpoint with URLSession; you need a Codable struct for the response. Generate it from a real payload instead of hand-typing nested fields.
SwiftUI previews: Paste a real API response, generate the struct, mock instances for #Preview blocks. Type-safe previews from real data.
Cross-platform projects: SwiftPM packages targeting both iOS and Linux server code share Codable types. Generate once, reuse everywhere.
Webhook payload handlers: Server-side Swift (Vapor / Hummingbird) handles webhooks; the vendor docs show JSON examples. Convert each to a typed Codable struct so your handlers stay refactor-safe.
Why Choose PDFFlare's JSON to Swift Codable Generator?
Codable Out of the Box
Every struct conforms to Codable and works with JSONDecoder directly — no custom decoders for snake_case-to-camelCase mapping.
Smart CodingKeys
CodingKeys enums included only when needed (snake_case keys, punctuation, reserved words) — clean output for camelCase APIs.
100% Browser-Based
JSON samples stay on your device — safe for production payloads.
No Signup Required
No account, no rate limits.
Frequently Asked Questions About JSON to Swift
PDFFlare's JSON To Swift tool runs entirely in your browser. Yes. Every struct conforms to Codable, so JSONDecoder().decode(Type.self, from: data) works directly. CodingKeys enums map snake_case JSON keys to camelCase Swift properties so you don't need a custom KeyDecodingStrategy.
Only when at least one JSON key doesn't match Swift naming (e.g. snake_case, kebab-case, leading digit, reserved word). If every key is already a valid camelCase identifier, the CodingKeys enum is omitted to keep the struct minimal.
Each unique object shape becomes its own struct. Names are inferred from property names (singularized for arrays of objects), giving you defaults like User, Post, Comment. Rename to fit your domain via find-and-replace.
The generator infers types from a single sample, so it can't know which fields are optional in the API contract. Mark fields as optional manually (Type?) where the API may omit them. JSONDecoder will throw .keyNotFound if a required field is absent in real data.
Yes. Whole-number values become Int; decimal values become Double. JSON treats both as 'number' but the converter inspects each value. For very large integers (e.g. 64-bit IDs), refine to Int64 manually.
Mixed-type arrays default to [String] since Swift doesn't have native unions. If you know the shape, refine manually with an enum + associated values, or use a custom decoder. The fixed-pattern fallback keeps the output compilable instead of forcing a complex union into the first generation.
No. The conversion runs entirely in your browser — safe for production payloads, internal API responses, and JSON containing tokens or PII. Nothing leaves your device.
Yes — Codable, JSONDecoder, and Swift's primitive types are all part of Foundation, available on every Apple platform (iOS, iPadOS, macOS, watchOS, tvOS, visionOS) and Swift on Linux. The generated structs are platform-agnostic.