How does JSON become a Swift Codable struct?
The converter infers Swift property types, creates a struct by default, and adds Codable conformance when that option is enabled.
Paste sample JSON and generate Swift models locally in your browser.
Use an object or an array of objects for model inference.
Generated code will appear here.Convert a JSON sample into Swift structs or classes with typed stored properties. Codable conformance can be included so the result fits native JSONEncoder and JSONDecoder workflows.
Nested objects become named Swift models. When a normalized Swift property name differs from its JSON key, the converter adds CodingKeys so decoding still uses the original payload.
Choose struct for value semantics or class for reference semantics, then select internal or public access. Properties can use immutable let declarations or mutable var declarations.
Optional output adds a question mark to fields that are missing or nullable in the samples. Codable and CodingKeys are emitted together when key mapping is necessary; already-safe matching keys do not receive redundant mappings.
Example JSON input:
{
"article_id": 9,
"author": {
"display_name": "Ada"
},
"published": true
}Generated Swift output:
struct RootModel: Codable {
let articleId: Int
let author: RootModelAuthor
let published: Bool
enum CodingKeys: String, CodingKey {
case articleId = "article_id"
case author
case published
}
}
struct RootModelAuthor: Codable {
let displayName: String
enum CodingKeys: String, CodingKey {
case displayName = "display_name"
}
}The converter infers Swift property types, creates a struct by default, and adds Codable conformance when that option is enabled.
CodingKeys appear when a safe generated property name differs from the original JSON key, such as converting article_id to articleId.
Use a struct for value semantics and independent copies. Choose a class when the model needs reference identity or class-specific behavior.
When optional properties are enabled, fields that are null or absent in some samples receive optional Swift types using a question mark.
Each nested object becomes a named Swift declaration. The parent property uses that type, and the nested declaration receives its own CodingKeys when needed.
Your JSON input, field names, root model name, and generated Swift source stay in this browser. They are not sent to a backend, added to the URL, or saved in local storage or cookies.
Compare another language-specific converter that uses the same local JSON inference engine.