🍎

JSON to Swift

Generate Swift structs with Codable from any JSON object

Input
Swift Struct
🔒 All processing runs in your browser. Your data is never sent to any server.

📖 What is this tool?

JSON to Swift Generator converts JSON objects into Swift structs conforming to the Codable protocol. Swift Codable structs can be decoded from JSON with just two lines of code — ideal for iOS and macOS development.

💡 Example

Input
{"id":1,"name":"Alice","active":true}
Output
struct Root: Codable { let id: Int let name: String let active: Bool }

🛠️ Common Use Cases

  • Generate Swift structs from API responses
  • Scaffold iOS data models from JSON
  • Create Codable types for URLSession
  • Convert API documentation to Swift models
  • Bootstrap Swift projects with data types

❓ Frequently Asked Questions

What is the Swift Codable protocol?
Codable (Encodable + Decodable) is a Swift protocol that enables automatic JSON encoding/decoding. Structs that conform to Codable can be decoded with: let obj = try JSONDecoder().decode(Root.self, from: jsonData)
How do I decode JSON in Swift?
let decoder = JSONDecoder(); let obj = try decoder.decode(Root.self, from: data). Use JSONDecoder.KeyDecodingStrategy.convertFromSnakeCase if your JSON uses snake_case keys.
Should I use struct or class for Swift data models?
Use struct for data models — they're value types (copied when assigned), which prevents many bugs caused by shared mutable state. Use class only when you need reference semantics or inheritance.
🔒
Your data stays private. All processing happens entirely in your browser. Nothing is ever sent to our servers. You can use this tool offline after the page loads.