HomeJSON ConvertersJSON to Swift

JSON to Swift

Convert JSON to Swift struct.

Convert JSON to Swift struct.

This tool is designed to provide a seamless experience for developers by handling complex operations directly in your browser with maximum speed and security.

100% Private
Instant Results
Customizable
Offline Ready
Dev-Friendly
Easy Export

Codable is a type alias for the Encodable and Decodable protocols, which can focus on encoding and decoding data, such as JSON, to and from Swift objects.

Read the Full Guide

This tool transforms JSON into clean, idiomatic Swift code, specifically generating structs that conform to the `Codable` protocol for modern iOS, macOS, watchOS, and tvOS development. It handles nested objects by creating multiple structs and maps JSON types to their Swift equivalents (String, Int, Double, Bool), including support for arrays and optional values. This is an essential tool for Swift developers who want to quickly integrate REST APIs or local JSON configuration files into their apps, ensuring that the data models are always perfectly synced with the incoming JSON payloads and leveraging the power of Swift's type system for safer data handling throughout the application life-cycle.

Input your JSON to generate Swift structs conforming to the `Codable` protocol. It handles nested objects by creating multiple structs.

Manually creating Swift structs for large and complex JSON responses can be a tedious and error-prone task. This tool automates the process, generating clean and typed Swift code that follows Apple's best practices for data decoding, saving you significant development time and helping you build more reliable and maintainable mobile and desktop applications.

Example Input

{
  "id": 1,
  "name": "John Doe",
  "email": "john@example.com",
  "isActive": true,
  "tags": ["admin", "dev"],
  "profile": {
    "bio": "Software Engineer",
    "skills": ["Go", "React", "TypeScript"]
  }
}

Example Output

struct User: Codable {
    let id: Int
    let name: String
    let email: String
    let isActive: Bool
}

Naming Conflicts

Fix: Swift uses camelCase. The tool automatically maps snake_case JSON keys to camelCase using `CodingKeys` if needed.

Does it support Optional types?

Yes, fields that are null in the JSON are automatically mapped to optional types (e.g., `String?`) in Swift.