JSON to Swift Codable Generator
Generate Swift structs conforming to Codable from a JSON sample, with camelCase properties, CodingKeys for renamed keys and optionals for missing values.
Free · No sign-up · Your inputs stay in your browser
Input
Generate Swift types from JSON
Output
Swift
488 characters
Structs conform to Codable. A key that is not a camelCase Swift name gets a CodingKeys entry, so JSONDecoder reads it without a global keyDecodingStrategy. Nullable or missing keys are optionals. Types come from this one sample: give fields that are null here a real value to type them.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
CodingKeys or a decoding strategy
JSONDecoder.keyDecodingStrategy = .convertFromSnakeCase converts snake_case keys for every type at once, which saves writing CodingKeys, but it applies to the whole decoder and cannot handle keys that are not snake_case. Explicit CodingKeys, as generated here, work with any decoder settings. Apple's Encoding and Decoding Custom Types article covers both.
Dates and numbers
Timestamps arrive as String here; set decoder.dateDecodingStrategy = .iso8601 and change the property to Date to decode them directly. Whole numbers become Int and fractions Double.