Skip to content
ToolsOnDuty - free online tools
Developer Tools

JSON to Swift Codable

Convert JSON into Swift Codable structs for iOS apps.

Free foreverRuns in your browserNo sign-up

Types are inferred from the sample JSON. Fields that are null become optional; check them against your real model.

About the JSON to Swift Codable

iOS and macOS apps decode JSON from APIs into Swift models. Writing those Codable structs by hand is tedious and error-prone.

This tool reads a JSON sample and generates Swift structs conforming to Codable, inferring types for strings, numbers, booleans, arrays and nested objects.

Everything runs in your browser, so your JSON never leaves your device.

Key features

  • Generates Codable structs from JSON
  • Infers Int, Double, Bool, String, arrays and nested types
  • Custom root type name
  • Local, private conversion

How to use

  1. 1Paste a JSON sample.
  2. 2Set the root type name if you like.
  3. 3Copy the generated Swift structs.

Examples

Simple model
Input: { "id": 1, "name": "Ada" }
Output: struct Root: Codable { let id: Int; let name: String }

Numbers become Int or Double and strings become String, all inside a Codable struct.

Frequently asked questions

Does it conform to Codable?
Yes. Every generated struct conforms to Codable, so you can decode and encode it with JSONDecoder and JSONEncoder out of the box.
How are null values handled?
A null becomes an optional String? because the real type cannot be inferred from null alone. Adjust it to the correct optional type for your model.
Can it handle nested objects and arrays?
Yes. Nested objects become their own structs and arrays become typed arrays based on the first element.