JSON to Swift Codable Generator
Generate Swift Codable structs with CodingKeys from JSON samples.
- 100% client-side · your data never leaves your browser
- Instant, no rate limits
- Free, no sign-up
Your result appears here
Paste JSON into the panel on the left — everything runs privately in your browser.
Overview
JSON to Swift Codable Generator — Structs Online
Generate Swift Codable structs from a JSON sample for your iOS, macOS, or server-side Swift app. JsonDrift infers property types, emits nested structs, and adds a CodingKeys enum whenever a property name differs from the JSON key — so JSONDecoder maps everything correctly. Private and client-side.
Why generate Codable structs from JSON?
Swift's Codable makes JSON decoding type-safe, but you still have to declare the structs. Writing them by hand for a nested API response is slow and easy to get wrong. Generating from a real payload gives you a correct set of Codable types you can decode immediately with JSONDecoder.
What gets generated
Objects become structs conforming to Codable; nested objects become their own structs. Strings map to String, whole numbers to Int, decimals to Double, booleans to Bool, and arrays to [T]. Property names are camelCased, and when a name differs from the JSON key a CodingKeys enum is emitted to map it.
- String, Int, Double, Bool, [T]
- Nested objects become nested Codable structs
- CodingKeys enum for keys that don't match property names
- import Foundation header included
Decoding with JSONDecoder
Paste the structs into your project and decode with try JSONDecoder().decode(Root.self, from: data). If your API uses snake_case keys, you can either keep the generated CodingKeys or set decoder.keyDecodingStrategy = .convertFromSnakeCase and drop them — both approaches work.
Review before shipping
Generated structs mirror one sample. Mark fields that may be absent as optional (T?), use Date with a dateDecodingStrategy for timestamps, and double-check numeric types — an id that arrives as a large integer may need Int64. Treat the output as a starting point you refine.
FAQ
Frequently asked questions
How do I convert JSON to Swift structs?
Paste a JSON sample and JsonDrift generates Codable structs with the correct types and CodingKeys, ready for JSONDecoder.
Does it add CodingKeys?
Yes. When a camelCased property name differs from the JSON key, a CodingKeys enum is emitted so decoding maps back to the original keys.
Are the structs Codable?
Yes. Every generated struct conforms to Codable, so it works with both JSONDecoder and JSONEncoder.
Is my JSON uploaded?
No. Generation runs entirely in your browser.
Continue with a related tool
All tools- JSON to Go Struct Generator
Infer Go struct definitions with JSON field tags from example JSON.
- JSON to Rust Struct Generator
Generate Rust serde structs with rename attributes from JSON samples.
- JSON to C# Class Generator
Generate C# classes with JsonProperty attributes from JSON examples.
- JSON to Java Class Generator
Generate Java classes with Jackson annotations from JSON samples.
- JSON to Kotlin Data Class Generator
Generate Kotlin data classes with @SerializedName from JSON samples.
- JSON to Python Converter
Generate Python dict literals or dataclass-style structures from JSON samples.