Skip to content
ToolsOnDuty - free online tools
Developer Tools

JSON to Swift Codable

Convert JSON into Swift Codable structs for iOS apps.

Free browser toolRuns in your browserNo sign-up
Swift model generator

Turn representative JSON into Swift models

Infer nested types and generate a copy-ready Codable struct starting from one realistic payload.

Swift

language

Root

root type

12 lines

output

Representative JSON

129 characters

Swift output

Generated locally

Types are inferred only from this sample. Null values become optional; verify optionality, coding keys and numeric ranges against the complete API contract.

Private by design. Input is processed inside this browser tab and is not sent to ToolsOnDuty.

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.

Open a related tool to prepare your files or refine the finished result.