Convert JSON to Swift
Codable struct or
Decodable class.
Generate Swift Codable structs and Decodable classes from any JSON. CodingKeys, optional properties, nested types and JSONDecoder usage snippet included. Runs entirely in your browser.
optional
— marked with ? in Swift.
| JSON value | Swift type | Optional |
|---|---|---|
"Alice" | String | String? |
42 | Int | Int? |
98.5 | Double | Double? |
true | Bool | Bool? |
null | AnyCodable? — refine manually | |
["a","b"] | [String] | [String]? |
[{…}] | [ChildType] | [ChildType]? |
{…} | ChildType | ChildType? |
iOS apps that call REST APIs with URLSession need Codable models to decode responses. Generate the model from a real API response, use JSONDecoder to decode, and access all fields with full Xcode autocomplete. Works identically with Alamofire's responseDecodable modifier.
Modern Swift apps use async/await for network calls. The generated Codable structs work directly with URLSession.shared.data(from:) and JSONDecoder — no callback nesting, no Combine overhead. Generate the model and drop it into your async function.
SwiftUI views are driven by @State, @ObservedObject and @StateObject. Make the generated Codable struct conform to Identifiable and ObservableObject to use it directly as a view model — no additional mapping layer needed between the JSON response and the view.
XCTest unit tests for network layer code need mock JSON responses decoded into Codable models. Generate the model from a real response JSON, create a mock URLProtocol that returns the same JSON, and assert that your network service decodes it correctly.
Swift models generated
in your browser. No Xcode needed.
The entire Swift code generation runs in JavaScript locally. Your JSON API response is never transmitted to any server. The generated code follows Swift conventions: PascalCase type names, camelCase property names, and the encoding/decoding patterns used throughout the Swift standard library.
CodingKeys are generated automatically when a JSON key differs from its camelCase equivalent — for snake_case APIs like first_name → firstName. Alternatively, set decoder.keyDecodingStrategy = .convertFromSnakeCase and skip CodingKeys entirely.
