What is JSON to Swift Struct Generator?
This tool converts JSON data into Swift struct definitions conforming to the Codable protocol. It automatically infers types, converts property names to camelCase (Swift convention), generates CodingKeys enums for JSON key mapping, and handles nested structs.
How to Use
- Set the root struct name and configure options (date detection)
- Paste your JSON data into the input area
- Click "Generate Swift Structs" and copy the output into your Xcode project
Why Use This Tool?
Tips & Best Practices
- Use realistic sample data — type inference depends on actual values
- CodingKeys are only generated when the Swift property name differs from the JSON key
- Null values in JSON are converted to optional types (String?)
- Date detection maps ISO-8601 strings to Swift Date type with Foundation import
Frequently Asked Questions
How are JSON types mapped to Swift?
JSON strings → String, integers → Int, floats → Double, booleans → Bool, null → T? (optional), arrays → [T], objects → separate nested structs. ISO-8601 date strings can be detected as Date when the option is enabled.
What is the CodingKeys enum?
The CodingKeys enum maps Swift property names to JSON keys. When a JSON key like "user_name" is converted to the Swift property "userName", the CodingKeys enum ensures the JSON decoder can find the correct key: case userName = "user_name".
Why use camelCase for property names?
Swift convention requires property names to use camelCase. This tool automatically converts snake_case, kebab-case, or PascalCase field names to camelCase while preserving the original JSON key in the CodingKeys enum.
What does Codable mean?
Codable is a Swift type alias that combines the Encodable and Decodable protocols. Structs conforming to Codable can be automatically encoded to and decoded from JSON using JSONEncoder and JSONDecoder.
Is my data sent to a server?
No, all processing happens entirely in your browser. Your JSON data never leaves your device.