JSON to Swift Codable Generator

Paste JSON, get Swift code instantly. Private, in your browser.

Input

Output

Ready
Ln 1, Col 1

Convert JSON to Swift in one step

Paste JSON and get Swift structs that conform to Codable, ready to decode with JSONDecoder in iOS, macOS, watchOS or server-side Swift.

How to use it

  1. Paste a JSON sample into the Input panel, open a file, or drop it onto the page. A sample is already loaded so you can see the result.
  2. The Swift code appears instantly in the Output panel and updates as you type.
  3. Rename the top-level type under Settings → Root type name, and use Sort keys to order fields alphabetically.
  4. Copy the code or Download it as Root.swift.

What the Swift generator produces

  • struct … : Codable for every object, with let properties.
  • A CodingKeys enum only when Swift names differ from the JSON keys.
  • Optional and nullable values become optionals (String?).
  • Mixed or null-only values use a small, included JSONAny enum.

Using the generated Swift code

Decode with JSONDecoder:

let decoder = JSONDecoder()
let data = try decoder.decode(Root.self, from: jsonData)
print(data.users[0].name)

More JSON tools

All tools are free and run privately in your browser.

JSON to Swift FAQ

What is JSONAny?

When a field has mixed types, or only null in your sample, the generator adds a small JSONAny enum that can decode and encode any JSON value.

Can I use snake_case conversion instead of CodingKeys?

Yes. Set decoder.keyDecodingStrategy = .convertFromSnakeCase and remove the CodingKeys enums for snake_case keys.

Is my data uploaded to a server?

No. The JSON to Swift runs entirely in your browser using JavaScript. Your data is never uploaded, logged or stored, and the tool keeps working offline after your first visit.