EN
My tools

JSON to Swift Codable Generator

Turn JSON into Swift Codable structs or classes with optionals, arrays, nested types, CodingKeys for snake_case keys and Date detection.

Swift code
Types generated
3

Set decoder.dateDecodingStrategy = .iso8601 for the Date properties. .iso8601 does not accept fractional seconds (2025-03-14T09:30:00.123Z); use a custom ISO8601DateFormatter with .withFractionalSeconds if your data has them. Plain dates (2025-03-14) also need a custom formatter.

CodingKeys map the JSON names to camelCase properties. Alternatively remove them and set decoder.keyDecodingStrategy = .convertFromSnakeCase.

A number written as 10.0 is read as a whole number, so a field whose samples are all like that becomes Int — include one sample with a fraction to get Double.

My tools →
Advertisement

Swift apps decode JSON with Codable, which needs a struct whose property names and types match the data exactly. Paste a sample response and get ready-made Codable types: nested objects become their own structs, arrays become [T], values that are null or missing in some samples become optionals, ISO 8601 strings become Date, and a CodingKeys enum maps snake_case JSON names to Swift's camelCase. Values with no single type get a small JSONValue enum instead of a guess.

How to use this tool

  1. Paste a representative JSON sample — arrays with several items give the best types.
  2. Enter the root type name.
  3. Choose struct or final class, let or var, and when properties are optional.
  4. Decide whether child types are nested inside their parent and whether dates become Date.
  5. Copy the code into a .swift file and decode with JSONDecoder.

Formula

whole number → Int · fraction → Double · true/false → Bool · text → String · ISO date → Date · [ … ] → [T] · { … } → struct

Values at the same place in different samples are merged: Int and Double become Double; anything mixed or always null becomes JSONValue. A property that is null in some sample or absent from some array item is optional. Identical shapes share one type; list element types are named from the singular of the key (orders → Order). Keywords such as default are written in backticks.

Example

The sample user gives three types. User has id: Int, name: String, isActive: Bool, balance: Double, createdAt: Date, tags: [String], address: Address, orders: [Order] and manager: JSONValue?, with CodingKeys for is_active and created_at. Order has orderId: String, total: Double, items: Int and coupon: String?, optional because only the second order has one.

Frequently asked questions

How do I decode the Date properties?

Set decoder.dateDecodingStrategy = .iso8601. That strategy rejects fractional seconds; if your timestamps have them, use an ISO8601DateFormatter with .withFractionalSeconds in a custom strategy.

CodingKeys or convertFromSnakeCase?

Either works. CodingKeys are explicit and survive renames; keyDecodingStrategy = .convertFromSnakeCase lets you delete them when every key is plain snake_case.

What is JSONValue?

An enum that can hold any JSON value. It is added only when a field has no single type in your samples, so the code still compiles; replace it with the real type when you know it.

Is my JSON uploaded?

No. The code is generated in your browser.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). JSON to Swift Codable Generator. https://kakao.mobile/tools/json-to-swift-codable/

MLA

“JSON to Swift Codable Generator.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/json-to-swift-codable/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement