Skip to content
Convertto

JSON to Swift Codable Converter

Convert JSON objects into strongly-typed Swift Codable definitions and data models.

To convert JSON to Swift Codable, paste your JSON payload above and specify the root type name. The generator creates clean, idiomatic Swift Codable code definitions instantly in your browser without uploading your JSON data to external servers.

Runs in your browser
Privacy
Runs entirely in your browser — nothing is uploaded
Cost
Free, unlimited, no sign-up

From a JSON sample to a Swift struct

The output is a struct conforming to Codable with let properties, which is the default shape for a decoded API response. JSONDecoder matches property names to keys by name, so a payload that is already camelCase decodes with no further work.

Where you will need to intervene

  • Snake_case keys. Either set keyDecodingStrategy to .convertFromSnakeCase on the decoder, or add a CodingKeys enum mapping each property to its raw key. The strategy is usually the smaller change, since the names here are already camelCased.
  • Optional keys. Swift decoding is strict: a key missing from the response throws keyNotFound rather than leaving the property empty. Any field the server may omit has to be declared with ?.
  • A JSON null in the sample yields Any?, which is not Codable and will not compile inside a Decodable type. Replace it with the concrete optional the field really holds.
  • Arrays are typed from the first element. A heterogeneous array needs a custom init(from:) or an enum with associated values.
  • Integer and floating point are read off the sample value, so Int will throw on a response that arrives with a decimal point.

For the Android half of the same API, JSON to Kotlin produces the equivalent data class, and JSON to Dart covers a Flutter client.

Frequently asked questions

Does this JSON to Swift Codable converter upload my files?

No, all type generation runs purely in JavaScript in your browser.

How to use the json to swift codable converter

  1. 1Enter or paste your json.
  2. 2Enter or paste your root type name.
  3. 3Press Run, then download the result when it is ready.

Sources & specifications

Embed this tool

Put the working json to swift codable converter on your own site. It runs in your visitors' browsers exactly as it does here — free, no account, nothing uploaded.

Share this tool

Last updated

More data & format tools