Swift struct will appear here
Paste JSON and click Generate// generate codable swift structs from json instantly
Convert JSON to Swift Codable structs instantly. Generate clean, type-safe Swift models for iOS and macOS development with optional properties and nested support.
Swift struct will appear here
Paste JSON and click GeneratePaste any valid JSON object or array of objects into the input panel.
Choose a root struct name and toggle options like public access or Foundation import.
Click Generate to produce Codable Swift structs. Copy or download the .swift file.
This tool generates Swift Codable structs from JSON input, automating the tedious task of writing model types for iOS and macOS. Paste your API response JSON and get production-ready Swift code in seconds.
Codable is a Swift type alias for Encodable & Decodable. When a struct conforms to Codable, Swift can automatically encode it to JSON and decode JSON into it — no manual mapping needed.
Yes. Any nested JSON object becomes its own separate Swift struct. The parent struct references the child by name, and all nested structs are output together so you can paste them directly into Xcode.
JSON keys like first_name are automatically converted to Swift-style camelCase properties (firstName). A CodingKeys enum is generated to bridge the original JSON key to the Swift property name.
Absolutely. The generated structs are standard Codable Swift types. Pass them to JSONDecoder().decode(Root.self, from: data) in any URLSession completion handler or async/await networking code.
Yes. If a JSON value is null, the corresponding Swift property is generated as an Optional (e.g., String?). For robust API parsing you can also manually add ? to any property you expect might be missing.
JSON booleans → Bool, integers → Int, floats → Double, strings → String, arrays → typed arrays like [String] or [ChildStruct], nested objects → named structs.
Yes. The generated structs are plain value types that work perfectly as SwiftUI data models. Add @Observable or wrap them in an ObservableObject class if you need state management.
No. All processing happens locally in your browser via JavaScript. Your JSON never leaves your machine, making this tool safe for sensitive API schemas and proprietary data structures.
Writing Swift data models by hand is one of the most repetitive tasks in iOS development. Every time you integrate a new API endpoint, you need to inspect the JSON response, map each key to a Swift property, infer types, handle nested objects, and write a CodingKeys enum whenever the server uses snake_case. This JSON to Swift Struct Generator automates all of that in a single click.
💡 Looking for premium iOS and Swift UI kits? MonsterONE offers unlimited downloads of app templates, UI components, and Swift design assets — worth checking out.
Paste any valid JSON object and the generator produces Swift structs that conform to the Codable protocol. Each key in your JSON becomes a typed Swift property. Nested objects become their own named structs. Arrays are typed correctly — [String], [Int], or [ChildStruct] depending on the contents. If a value is null, the property is marked optional with a ? suffix.
When JSON keys use snake_case or other non-camelCase conventions, the generator automatically creates a CodingKeys enum that maps the original JSON key to a proper Swift property name. This follows Swift's official API Design Guidelines, which call for camelCase property names.
Introduced in Swift 4, Codable is a type alias combining the Encodable and Decodable protocols. When a type conforms to Codable, the Swift compiler synthesizes the encoding and decoding logic automatically — as long as all stored properties are themselves Codable.
This means you can decode a JSON response from a URLSession request with just two lines:
let decoder = JSONDecoder() let result = try decoder.decode(Root.self, from: data)
No third-party libraries. No custom parsing logic. No fragile string subscripts. Codable is the modern, recommended way to handle JSON in Swift across all Apple platforms.
Once you generate your structs, you can paste them into a new .swift file in Xcode. If you enabled the import Foundation option, the import statement is already included. Rename the root struct to match your domain model, adjust any property types if needed, and start decoding immediately.
For SwiftUI projects, the structs work as @State values or inside ObservableObject classes. For UIKit apps, they integrate seamlessly with any data layer, whether you're using MVVM, Combine, or async/await with structured concurrency.
Real-world API responses are rarely flat. They contain nested objects, arrays of objects, nullable fields, and mixed-type arrays. Here is how the generator handles each case:
[ChildStruct]. The generator inspects the first element of the array to determine the struct shape.[String], [Int], or [Double] as appropriate.null values are generated as optionals (Type?).CodingKeys enum for lossless round-tripping.Understanding how JSON types map to Swift types helps you verify and tweak the generated output:
true / false → BoolIntDoubleStringnull → OptionalType?[String][StructName]structThe generated code is a solid starting point, but real-world models often need a few tweaks. Consider these refinements after generating your structs:
String. Change them to Date and configure JSONDecoder().dateDecodingStrategy = .iso8601.String with a RawRepresentable enum for type safety.Identifiable to structs used in SwiftUI List views.Hashable if you need to store instances in sets or use them as dictionary keys./// doc comments to generated properties for better Xcode autocomplete experience.JSONDecoder has a built-in .convertFromSnakeCase key decoding strategy that handles snake_case conversion automatically. However, explicit CodingKeys enums are often preferred in production code because they make the JSON contract explicit and visible, they survive refactoring without silent breakage, and they allow per-property customization beyond simple case conversion. This generator gives you the explicit version, which is safer for long-lived production codebases.
The generated Swift structs are compatible with Swift 5.5+ and work on iOS 13+, macOS 10.15+, watchOS 6+, tvOS 13+, and visionOS 1+. The Codable protocol has been stable since Swift 4, so the output is broadly compatible across Xcode versions and Apple developer toolchains.