JSON to Swift Codable struct
Turn a JSON sample into a Swift struct that conforms to Codable.
JSON to Swift Codable struct
Paste a JSON sample and this tool infers its shape and generates a Swift struct that conforms to Codable, ready to drop into an iOS, macOS or server-side Swift project. Nested objects become their own nested structs, arrays become typed Swift arrays, and a value that is sometimes missing or null becomes an optional property with a question mark — so the generated model matches what the API actually sends, not just one lucky sample.
The options control the shape of the generated code. Choose struct or class for the declaration, and let or var for property mutability. Turning on CodingKeys converts snake_case JSON keys such as user_name into Swift's camelCase convention and adds the matching CodingKeys enum, so decoding still lines up with the original field names; leave it off to keep the JSON keys verbatim. Access level sets whether the type and its properties are public or internal, dates as Date recognises ISO-8601 strings and types them as Date instead of String, and indentation lets you match your project's style with 2 spaces, 4 spaces or tabs.
A field that mixes unrelated types across a sample array — a value that is sometimes a number and sometimes a string — falls back to a small AnyCodable wrapper that is only added to the output when it is actually needed, so the struct still compiles instead of silently guessing wrong. Keys that aren't valid Swift identifiers, including emoji or keys starting with a digit, are sanitized and mapped back through CodingKeys automatically so nothing is lost.
Everything runs locally in your browser as you type — no JSON sample is ever uploaded or sent to a server, which matters when the sample comes from a real API response. Copy the generated Swift, download it as a .txt file, or send it back into the input to refine it further.