One-click convert JSON data to Swift struct and Codable definitions with nested structs and CodingKeys
Zero Dependencies · Works OfflineThe JSON to Swift Struct Converter is a free online developer tool that instantly converts JSON data into Swift struct definitions. It automatically identifies JSON field types and maps them to Swift types, supporting nested object struct generation, Codable protocol conformance, CodingKeys enum mapping, and optional type handling. Perfect for iOS/macOS developers who need to quickly generate model definitions from API responses, dramatically reducing manual struct writing. All conversion happens locally in your browser — no data is ever uploaded to a server.
1. Paste your JSON data into the input area, or click "Load Example" to try it quickly.
2. Set the struct name and conversion options: Codable, optional types, CodingKeys, etc.
3. Click "Convert" or use Ctrl+Enter to execute.
4. View the generated Swift struct code in the result area below.
5. Click "Copy Code" to copy to clipboard, or download as a .swift file.
When integrating REST APIs, paste the JSON response to instantly generate Codable structs for use with JSONDecoder.
Vapor or Perfect backend developers can quickly generate model structs from request body JSON samples.
Quickly generate ObservableObject or Model struct definitions from JSON data in SwiftUI projects.
Generate Swift model definitions from shared JSON schemas, keeping data consistent across platforms.
Swift's Codable protocol, introduced in Swift 4, combines Encodable and Decodable for type-safe encoding/decoding. Any Codable type can be encoded to JSON with JSONEncoder and decoded from JSON with JSONDecoder. When Swift property names differ from JSON keys (e.g., Swift uses camelCase isVip while JSON uses is_vip), a CodingKeys enum provides the mapping. Optional types (Type?) are a core Swift feature that precisely distinguishes between having a value and being nil, and with Codable they automatically handle potentially missing JSON fields. Swift 5.9+ macros further simplify Codable usage.
Yes. Nested objects are automatically generated as separate struct definitions.
With "Optional types" enabled, null fields generate optional types (e.g., String?) for safe decoding.
Yes. Structs conform to Codable by default, ready for JSONEncoder/JSONDecoder.
No. All processing happens locally in your browser. Your data never leaves your device.
CodingKeys enums map Swift property names to JSON keys when they differ, ensuring correct encoding/decoding.
Yes. The output follows Swift conventions and can be copied directly into a .swift file.