🔄 JSON to Swift Struct

One-click convert JSON data to Swift struct and Codable definitions with nested structs and CodingKeys

Zero Dependencies · Works Offline

📝 JSON Input

What is JSON to Swift Struct Converter?

The 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.

Core Features

How to Use

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.

Use Cases

iOS App Development

When integrating REST APIs, paste the JSON response to instantly generate Codable structs for use with JSONDecoder.

Swift Backend

Vapor or Perfect backend developers can quickly generate model structs from request body JSON samples.

SwiftUI Data Models

Quickly generate ObservableObject or Model struct definitions from JSON data in SwiftUI projects.

Cross-Platform Projects

Generate Swift model definitions from shared JSON schemas, keeping data consistent across platforms.

Technical Background

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.

âť“ FAQ

Does it support nested JSON?

Yes. Nested objects are automatically generated as separate struct definitions.

How are null values handled?

With "Optional types" enabled, null fields generate optional types (e.g., String?) for safe decoding.

Does it support Codable?

Yes. Structs conform to Codable by default, ready for JSONEncoder/JSONDecoder.

Is my data uploaded?

No. All processing happens locally in your browser. Your data never leaves your device.

What are CodingKeys?

CodingKeys enums map Swift property names to JSON keys when they differ, ensuring correct encoding/decoding.

Can generated code be used directly?

Yes. The output follows Swift conventions and can be copied directly into a .swift file.

JSON to Swift Struct Converter | No Signup, Client-Side · No Server Uploads

Feedback: dexshuang@google.com