Skip to JSON input
Runs in your browser. Your JSON stays on this device.

JSON to Swift Converter

Paste an API response and get Codable Swift structs you can drop straight into Xcode, with CodingKeys, optionals and nested types worked out for you.

Access
Model options

JSON

Output updates as you type. Press Ctrl/⌘ + Enter to convert immediately.

Swift

Your Swift models will appear here

Paste JSON on the left, upload a file, or start from the sample.

Turn JSON into Swift models in seconds

Writing Codable structs by hand for every API response is slow and easy to get wrong: one misspelled key or a missing optional and JSONDecoder throws. This JSON to Swift converter reads a real JSON sample, works out the type of every value, and writes idiomatic Swift for you, including CodingKeys for keys that are not valid Swift names.

Everything runs locally in your browser. Your JSON is never uploaded, so it is safe to use with private or production payloads.

How to use

  1. Add your JSON. Paste it into the JSON panel, drop a .json file onto it, or choose Upload .json.
  2. Set the options. Name the root struct, choose internal or public, and decide how optionals and Identifiable should work. The output updates immediately.
  3. Review the notices. Anything the sample could not answer, such as an always-empty array, is listed under the output with its JSON path.
  4. Copy or download. Add the file to Xcode and decode with JSONDecoder().decode(Response.self, from: data).

Features

Nested types
Nested objects become their own structs, and arrays of objects get a correctly named element type such as [User] for users.
Accurate optionals
Null values become optionals. Keys missing from some array items are optional too, so decoding real data does not fail.
Clean names
snake_case, kebab-case and spaced keys become camelCase properties, with CodingKeys generated only when needed.
Swift keywords
Keys such as default, class or self are escaped with backticks or safely renamed.
No duplicate types
Identical shapes share one struct. Conflicting names are disambiguated, and names that would shadow Data, URL or Date are avoided.
Honest inference
Mixed types, empty arrays and values that are always null are typed as JSONValue and flagged, never guessed silently.
Dictionaries
Objects keyed by IDs, UUIDs or dates become [String: Value] dictionaries instead of structs with odd property names.
Ready for frameworks
Choose public access and the converter adds the public initializer Swift does not synthesize for you.

Example

This JSON:

{
  "id": 42,
  "full_name": "Ada Lovelace",
  "is_admin": false,
  "last_login": null,
  "roles": [{ "id": "r1", "title": "Editor" }]
}

becomes (the JSONValue helper is omitted here):

struct Response: Codable {
    let id: Int
    let fullName: String
    let isAdmin: Bool
    let lastLogin: JSONValue
    let roles: [Role]

    enum CodingKeys: String, CodingKey {
        case id
        case fullName = "full_name"
        case isAdmin = "is_admin"
        case lastLogin = "last_login"
        case roles
    }
}

struct Role: Codable {
    let id: String
    let title: String
}

last_login is only ever null in this sample, so its real type is unknown. The converter flags it and you can replace JSONValue with Date? or String?.

Frequently asked questions

How do I convert JSON to a Swift model?

Paste your JSON into the input panel or upload a .json file. The converter generates Codable Swift structs as you type. Copy the code or download it as a .swift file, add it to your Xcode project, then decode with JSONDecoder.

Is my JSON sent to a server?

No. Parsing and code generation run entirely in your browser with JavaScript. Nothing is uploaded, logged or stored on a server.

How are null values and missing keys handled?

A property that is null in your sample becomes an optional. When an array contains objects and a key appears in only some of them, that property also becomes optional so decoding does not fail. A value that is only ever null has no known type, so it is generated as JSONValue, which keeps an explicit null as .null, and is flagged with a warning.

What happens to keys that are not valid Swift names?

Keys are converted to camelCase property names and mapped back to the original key with CodingKeys. Keys with spaces, hyphens or leading digits are converted, and Swift keywords such as default or class are escaped with backticks.

What is JSONValue in the generated code?

JSONValue is a small Codable enum included only when needed. It represents values whose type cannot be inferred from the sample, such as arrays with mixed types, empty arrays or values that are always null. Each use is listed in the notices so you can replace it with a concrete type.

Which Swift versions are supported?

The generated code uses standard Codable APIs and works with Swift 5 and Swift 6, on iOS, macOS, watchOS, tvOS, visionOS and Linux.