Output will appear here
Output will appear here
Convert JSON to Swift Codable structs with CodingKeys enums and properly typed properties. This free JSON to Swift converter generates production-ready structs for use with JSONDecoder in iOS, macOS, and server-side Swift projects.
Try Convert All - paste JSON once, see TypeScript, Go, YAML, and 15 more formats instantly.
Paste a JSON object or array into the editor. The converter accepts any valid JSON including arrays of heterogeneous objects and deeply nested structures.
The output pane shows Swift structs conforming to the Codable protocol. Each struct includes stored properties with correct Swift types and a CodingKeys enum when JSON keys differ from Swift naming conventions.
Copy the generated code into a .swift file in your project. Decode JSON data using JSONDecoder().decode(Root.self, from: data) with no additional configuration needed.
Paste your JSON here to generate Codable structs, then use JSONDecoder in your Swift code: let result = try JSONDecoder().decode(Root.self, from: jsonData). The generated structs handle all the mapping between JSON keys and Swift properties automatically.
CodingKeys is a private enum inside a Codable struct that maps JSON key names to Swift property names. The converter generates it whenever a JSON key like "user_name" needs to map to a Swift property like userName, or when keys contain characters invalid in Swift identifiers.
Yes. The generated structs conform to Codable, which is the standard protocol used by URLSession, Combine publishers, and SwiftUI data flows. You can decode API responses directly into these structs and bind them to SwiftUI views.
Each nested object becomes a separate struct named after its parent key in PascalCase. The parent struct holds a property of that nested type. For example, a "shipping_info" key generates a ShippingInfo struct and a var shippingInfo: ShippingInfo property.
Fields with null values in your JSON are automatically typed as optionals (e.g., String?). For fields that exist in your sample but might be absent in other responses, you can manually add a question mark after generation to make them optional.