{ }jsonkit
Format
Validate
Convert
Query
Generate

JSON to Swift Codable struct generator

Generate Codable structs with optionals, arrays and CodingKeys.
353 B · paste or drop a file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
✓ complete353 B → 2162 B0.0 ms

About JSON to Swift

The JSON to Swift generator builds nested structs from a sample JSON response. Objects map to structs and arrays to typed Swift arrays. Strings become String, booleans Bool and numbers Int or Double. Null or missing values become optionals.

Codable mode makes the models ready for JSONEncoder and JSONDecoder. It adds CodingKeys when the camelCase property name differs from the JSON key. Choose let for immutable response models, or var when your app edits decoded values.

Runs in your browser. Nothing is uploaded. Treat the result as a scaffold. A JSON sample cannot prove date formats, enum cases, decimal precision, optional fields outside the sample or polymorphic responses.

How it works

Generate Swift structs recursively

The root object becomes Root, and each nested object is named after its key. Arrays of objects are merged into one element struct. It keeps every key seen in the sample and makes partly present members optional.

Create Codable and CodingKeys

Codable mode adds Codable conformance. When a key such as user_id or created-at becomes a Swift property name, a CodingKeys enum maps it back to the exact JSON key for encoding and decoding.

Infer optionals and numeric types

Nulls and keys missing from some array elements get a question mark. Whole numbers become Int and decimals become Double. If a value can exceed Int on the target platform or needs exact money math, change it to Int64 or Decimal.

Choose immutable or mutable properties

The default let output suits decoded API responses and predictable state. Turn on mutable properties to get var when the model is edited before display, storage or re-encoding.

Frequently asked questions

Will the generated Swift models decode immediately?

A complete sample with consistent arrays usually gives Codable structs that work as is. Empty or mixed arrays may need a concrete type by hand. API-specific dates or polymorphic responses still need a decoder strategy or custom code.

Why is a property optional?

The value was null, or the key was missing in at least one object of a sampled array. The generator cannot find optional keys that are present everywhere in your sample, so check them against the endpoint docs.

Does it recognize ISO 8601 dates automatically?

No. JSON stores dates as strings, and guessing from a date-like pattern can mislead. The output keeps String so you can choose Date, set JSONDecoder.dateDecodingStrategy or keep the original text.

Is the pasted JSON private?

Yes. The sample is parsed and converted in your browser and is not uploaded.

Sources & last verified

We checked this tool's behavior and the claims on this page against the specifications below on . The tool runs in your browser, so the output you see is exactly what the engine produced.

Found a wrong result or an outdated claim? Report an error and we will check it again.