Paste a JSON sample and get clean Swift Codable structs — nested objects become their own structs, arrays and optionals are inferred, and a CodingKeys enum is added only when a key differs. Fast, secure, and entirely in your browser.
No installation, no signup. Results in milliseconds.
A JSON to Swift converter reads a sample of JSON and writes the Swift structs that describe its shape, each conforming to Codable so you can decode it with JSONDecoder. Instead of hand-writing a model for every API response, you paste the response and get types you can drop straight into your app.
Swift needs a concrete type to decode JSON into, and writing those structs by hand for a large payload is slow and easy to get wrong, especially the CodingKeys that map camelCase properties to snake_case keys. Generating them from a real sample means the types and keys match the data exactly.
[String], [Item]).T?) for fields that are missing or null.These are the inference rules the converter applies so the output is predictable.
| JSON | Becomes in Swift |
|---|---|
Object { } | A struct conforming to Codable. |
| Nested object | Its own named struct, referenced from the parent property. |
Array [ ] | A Swift array such as [String] or [Item]. |
| Whole number | Int. |
| Decimal number | Double. |
| string / boolean | String / Bool. |
| Missing key / null | An optional, such as Int?. |
| null only / mixed types | AnyCodable (needs the AnyCodable package). |
A property becomes optional (T?) when its key is missing from some objects in an array, or when its value is sometimes null, so decoding to nil works as Swift expects. A CodingKeys enum is emitted only when at least one property name differs from its JSON key, for example a camelCase property for a snake_case key; when every key already matches, no enum is needed. Validate the JSON first with the JSON parser if it will not convert, or tidy it in the JSON formatter.
AnyCodableA field that is only ever null, an empty array, or holds more than one unrelated type has no single Swift type, so it is typed AnyCodable. Add the small AnyCodable Swift package, or replace it with a concrete type once you paste a fuller sample. For a deeply nested payload, expanding it in the JSON viewer first helps you confirm the shape.
See how a nested object with a snake_case key becomes clean Codable structs.
Notice three things: items became its own Item struct and an array, total is a Double because the sample has a decimal, and a CodingKeys enum appears only because order_id maps to the camelCase orderId. For the step-by-step reasoning, see our guide on converting JSON to Swift structs.
Typed Codable models from real data, in seconds.
Everything developers ask about generating Swift structs from JSON.
Codable, so you can decode with JSONDecoder().decode(Root.self, from: data) and encode the same types back to JSON with JSONEncoder.snake_case key. If every key is already a valid matching identifier, no CodingKeys enum is needed and none is emitted.T?) when its key is missing from some objects in an array, or when its value is sometimes null. Optional properties decode to nil when the key is absent, which is exactly how Codable expects them.Int and numbers with a decimal point become Double, matching how Swift's JSONDecoder reads them.AnyCodable. Add the AnyCodable Swift package, or replace it with a concrete type once you have a fuller sample.let value = try JSONDecoder().decode(Root.self, from: data). Because the structs are Codable, encoding back to JSON works the same way with JSONEncoder.Hands-on articles from our blog.
All free, all browser-based, no signup required.