Free JSON to Swift — Codable · struct · class · JSONDecoder

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.

Your data never leaves your browser
Codable struct · Decodable class
CodingKeys for snake_case APIs
Optional for nullable fields
Always free
JSON to Swift Model Generator   100% client-side
Use a representative JSON sample with non-null values. Null fields become optional — marked with ? in Swift.
JSON input
  Swift model ready

      
How JSON types map to Swift types
JSON valueSwift typeOptional
"Alice"StringString?
42IntInt?
98.5DoubleDouble?
trueBoolBool?
nullAnyCodable? — refine manually
["a","b"][String][String]?
[{…}][ChildType][ChildType]?
{…}ChildTypeChildType?
When do you need JSON to Swift models?
URLSession and Alamofire

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.

Swift Concurrency (async/await)

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 data models

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.

Unit test fixtures

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.

Popular searches
json to swift model json to swift struct json to swift codable json to swift json swift codable struct json to swift converter json to swift class convert json to swift model json to swift codable online json to swift model online json to swiftui model

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.

Auto CodingKeys
Generated automatically when JSON keys differ from camelCase — maps snake_case, kebab-case and any other convention to Swift property names.
3 output styles
Codable struct (encode + decode), Decodable struct (decode only) and Codable class (reference type for ObservableObject).
JSONDecoder snippet
Usage snippet included at the bottom — ready-to-paste JSONDecoder code with dateDecodingStrategy and keyDecodingStrategy options.
47 tools, always free
No file size limits, no watermarks, no account. Funded by non-intrusive display advertising only.
Frequently asked questions
How do I convert JSON to a Swift Codable struct?
Paste your JSON, set the struct name, choose Codable struct style, and click Generate. Copy the output into your Swift project and use JSONDecoder().decode(Root.self, from: data) to deserialize. The struct conforms to both Encodable and Decodable.
When should I use struct vs class for Codable models?
Use struct (value type) for most API response models — they are safer, more predictable and work well with SwiftUI's data flow. Use class (reference type) when you need inheritance, ObservableObject conformance for SwiftUI @ObservedObject, or when multiple parts of your app need to share the same instance.
How do I decode JSON with snake_case keys in Swift?
Two options: 1) Use CodingKeys enum to map each snake_case key to a camelCase property — the generator does this automatically. 2) Set decoder.keyDecodingStrategy = .convertFromSnakeCase — this handles all fields automatically without CodingKeys. The second option is cleaner for APIs that consistently use snake_case throughout.
Is the JSON to Swift converter free?
Yes, completely free. No file size limits, no account required. JSONshift is funded by non-intrusive display advertising.
Go up