What this does
Generates Swift struct (or class) declarations from a JSON sample. Turn Types only off to make them Codable and addCodingKeys, so JSONDecoder can read your payload directly.
Example
Input
{
"id": 42,
"name": "Ada",
"verified": true,
"tags": [
"admin",
"dev"
],
"orders": [
{
"sku": "A1",
"qty": 2
},
{
"sku": "B2",
"qty": 1,
"note": "gift"
}
]
}Output with default options
import Foundation
// MARK: - Root
struct Root {
let id: Int
let name: String
let verified: Bool
let tags: [String]
let orders: [Order]
}
// MARK: - Order
struct Order {
let sku: String
let qty: Int
let note: String?
}
How values are mapped
- Whole numbers become
Int, other numbersDouble, stringsString, booleansBool. - Arrays become
[T]; a field missing from some objects becomesT?. - ISO 8601 timestamps become
Datewhen date detection is on. - Arrays of mixed types become an
enumwith an associated value per type.
Options
Choose struct or class, internal or public access, andlet or var properties. Generate CodingKeys maps Swift-style names back to the original JSON keys when you want a Codable result.
Things to know
Property names become lowerCamelCase, so user_id turns intouserID. Swift has no way to decode a bare null value into a useful type, so a field that is always null becomes NSNull; replace it by hand once you know the real type.
Privacy
Generation runs in a Web Worker in your browser. The JSON is never uploaded.