# JSON to Swift Codable Converter

> Convert JSON objects into strongly-typed Swift Codable definitions and data models.

To convert JSON to Swift Codable, paste your JSON payload above and specify the root type name. The generator creates clean, idiomatic Swift Codable code definitions instantly in your browser without uploading your JSON data to external servers.

**URL:** https://convertto.tech/t/json-to-swift
**Category:** Data & Format Tools (https://convertto.tech/c/data-tools)
**Privacy:** Runs entirely in the browser; no upload
**Cost:** Free, no sign-up
**Last updated:** 2026-08-01

## Key facts

- **Privacy:** Runs entirely in your browser — nothing is uploaded
- **Cost:** Free, unlimited, no sign-up

## From a JSON sample to a Swift struct

The output is a `struct` conforming to `Codable` with `let` properties, which is the default shape for a decoded API response. `JSONDecoder` matches property names to keys by name, so a payload that is already camelCase decodes with no further work.

## Where you will need to intervene

- Snake_case keys. Either set `keyDecodingStrategy` to `.convertFromSnakeCase` on the decoder, or add a `CodingKeys` enum mapping each property to its raw key. The strategy is usually the smaller change, since the names here are already camelCased.
- Optional keys. Swift decoding is strict: a key missing from the response throws `keyNotFound` rather than leaving the property empty. Any field the server may omit has to be declared with `?`.
- A JSON `null` in the sample yields `Any?`, which is not `Codable` and will not compile inside a `Decodable` type. Replace it with the concrete optional the field really holds.
- Arrays are typed from the first element. A heterogeneous array needs a custom `init(from:)` or an enum with associated values.
- Integer and floating point are read off the sample value, so `Int` will throw on a response that arrives with a decimal point.

> **A date is not a JSON type** — Timestamps arrive as a string or a number, so they infer as `String` or `Int`. Change the property to `Date` and set a matching `dateDecodingStrategy` such as `.iso8601`, rather than parsing the string later in a view where the failure has nowhere to go.

For the Android half of the same API, [JSON to Kotlin](https://convertto.tech/t/json-to-kotlin) produces the equivalent data class, and [JSON to Dart](https://convertto.tech/t/json-to-dart) covers a Flutter client.

## How to use

1. Enter or paste your json.
2. Enter or paste your root type name.
3. Press Run, then download the result when it is ready.

## FAQ

### Does this JSON to Swift Codable converter upload my files?

No, all type generation runs purely in JavaScript in your browser.

## Sources

- [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259) — IETF
- [Apple Developer: JSONDecoder](https://developer.apple.com/documentation/foundation/jsondecoder) — Apple

## Related tools

- [JSON to C# Model Converter](https://convertto.tech/t/json-to-csharp): Convert JSON objects into strongly-typed C# Model definitions and data models.
- [JSON to Dart Class Converter](https://convertto.tech/t/json-to-dart): Convert JSON objects into strongly-typed Dart Class definitions and data models.
- [JSON to Go Struct Converter](https://convertto.tech/t/json-to-go): Convert JSON objects into strongly-typed Go Struct definitions and data models.
- [JSON to Java Class Converter](https://convertto.tech/t/json-to-java): Convert JSON objects into strongly-typed Java Class definitions and data models.
- [JSON to Kotlin Data Class Converter](https://convertto.tech/t/json-to-kotlin): Convert JSON objects into strongly-typed Kotlin Data Class definitions and data models.
- [JSON to Mongoose Schema Converter](https://convertto.tech/t/json-to-mongoose): Convert JSON objects into strongly-typed Mongoose Schema definitions and data models.
- [JSON to Prisma Model Converter](https://convertto.tech/t/json-to-prisma): Convert JSON objects into strongly-typed Prisma Model definitions and data models.
- [JSON to Python Dataclass Converter](https://convertto.tech/t/json-to-python): Convert JSON objects into strongly-typed Python Dataclass definitions and data models.
