Swift types from a JSON sample
Paste a JSON document and get Codable structs for it. Each object shape becomes a struct, arrays become [T], and a CodingKeys enum pins every property to the key it came from.
Example
import Foundation
struct Customer: Codable {
let id: Int
let name: String
let orders: [Order]
}
struct Order: Codable {
let sku: String
let qty: Int
let gift: Bool?
}
gift is Bool? because only some orders in the sample carry it. With Initializers on, each struct also gets init(data:), init(_ json:), and jsonData() built on JSONDecoder and JSONEncoder.
Options
Kind switches between struct and class. var instead of let makes properties mutable. Access sets internal or public on every declaration, for types shipped in a framework. Conformance adds Equatable or Hashable alongside Codable. Sendable marks the types for Swift concurrency. Type prefix prepends a string to every type name, the old Objective-C habit, when the generated names would collide with ones in your module.
Limits
Swift has no anonymous union type, so a field that mixes types in the sample becomes an enum with one associated-value case per type and a hand-written init(from:). Repeated string values become a String-backed enum when enum inference is on. Dates become Date only when date inference is on, and the decoder in the generated initializers is configured for ISO 8601.