JSON to Swift
Paste JSON — get Swift Codable structs as you type. Nothing leaves your browser.
› More options & type detection
JSON to Swift example
Turn a JSON response into Swift models for an iOS or macOS app. Each object becomes a struct that conforms to Codable, with CodingKeys that map Swift names back to the original JSON keys, so JSONDecoder can decode it directly.
{
"todos": [
{
"id": 7,
"title": "Ship the iOS app",
"isDone": false,
"dueDate": "2026-11-01",
"tags": [
"release"
],
"assignee": {
"login": "ada",
"avatarUrl": "https://example.com/ada.png"
}
},
{
"id": 8,
"title": "Write release notes",
"isDone": true,
"tags": [],
"assignee": null
}
]
}// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse the JSON, add this file to your project and do:
//
// let todoList = try? JSONDecoder().decode(TodoList.self, from: jsonData)
import Foundation
// MARK: - TodoList
struct TodoList: Codable {
let todos: [Todo]
enum CodingKeys: String, CodingKey {
case todos = "todos"
}
}
// MARK: - Todo
struct Todo: Codable {
let id: Int
let title: String
let isDone: Bool
let dueDate: String?
let tags: [String]
let assignee: Assignee?
enum CodingKeys: String, CodingKey {
case id = "id"
case title = "title"
case isDone = "isDone"
case dueDate = "dueDate"
case tags = "tags"
case assignee = "assignee"
}
}
// MARK: - Assignee
struct Assignee: Codable {
let login: String
let avatarURL: String
enum CodingKeys: String, CodingKey {
case login = "login"
case avatarURL = "avatarUrl"
}
}
- Codable with CodingKeys
- Every struct conforms to Codable and lists a CodingKey with the original JSON key for each property. Keep “Explicit CodingKey values in Codable types” on: without it, renamed properties such as avatarURL no longer match their JSON key.
- Swift-style names
- avatarUrl becomes avatarURL, and the CodingKey keeps "avatarUrl" so decoding still works. Change Acronym naming style to keep names as they are.
- Optionals from your samples
- dueDate is missing from the second todo and assignee is null there, so both become optionals. Paste several real responses to get the optionals right.
- Structs, lets and protocols
- Properties are let constants on structs by default. Options switch to classes or var properties, add Equatable, Hashable or Sendable, make types public, or turn on initializers and mutators.
Convert JSON to any language
The same smart type inference, 28 output formats.
Types that match your real data
Built on the open-source quicktype engine, with quieter defaults and a friendlier editor.
- Optional fields detected
- Fields that are missing or null in some items become optional automatically.
- Merge many samples
- Paste JSON Lines or an array — every example contributes to one accurate type.
- Paste anything
- JavaScript objects, trailing commas, single quotes and comments are repaired for you.
- Sensible defaults
- No surprise enums or date classes — turn detection on only when you want it.
- Every option, every language
- All of Swift’s generator settings, from naming style to framework annotations.
- Private & instant
- Runs in a background thread in your browser. Share links keep data in the URL only.
Frequently asked questions
How do I convert JSON to Swift Codable?+
Paste your JSON and copy the generated structs into your project. The comment at the top shows the decode call, for example try? JSONDecoder().decode(TodoList.self, from: jsonData).
How are dates handled?+
Date strings stay String by default. Turn on Detect dates to type ISO-8601 strings as Date, and decode with a JSONDecoder whose dateDecodingStrategy matches your format, such as .iso8601.
What is the JSONNull class in my output?+
It appears when a field is null in every sample, so its real type is unknown. Paste a sample where the field has a value and it is replaced with a proper type.
What if my samples have different fields?+
Paste several samples as JSON Lines (one JSON value per line) or as an array of objects. They are merged into one type, and fields missing from some samples become optional.
Can I paste a JavaScript object from the console?+
Yes. Unquoted keys, single quotes, trailing commas and comments are repaired automatically before the types are generated.
Is my data uploaded?+
No. The conversion runs entirely in your browser, in a background thread. Nothing is sent to a server.
Why don’t I see enums or date types?+
By default, string fields stay strings so the output matches your JSON exactly. Turn on “Detect enums” or “Detect dates” under Options to generate enum and date types.
Code generation uses quicktype (Apache-2.0 license).