Online Tool Store Online Tool Store

Swift Codable Generator

Paste a sample JSON object and generate matching Swift Codable structs, including nested types and CodingKeys enums for snake_case field names.

🔒 This tool runs entirely in your browser. Your files are never uploaded to a server.

Example shown. Nested objects become nested structs; arrays of objects reuse the same generated type.

How the Swift Codable Generator works

  1. Paste a sample JSON object (or array of objects) into the left panel.
  2. The tool walks the JSON tree, inferring a Swift type for every field and generating one struct per object shape it encounters.
  3. Copy the generated Codable structs, including CodingKeys enums for any snake_case-to-camelCase renames.

Type inference rules

Strings map to String, whole numbers to Int, decimals to Double, booleans to Bool, objects to a nested Codable struct, and arrays to a Swift array of whichever type their elements resolve to.

FAQ

How does it handle snake_case JSON keys?

When a JSON key like "user_name" is converted to camelCase ("userName") for the Swift property, the tool automatically adds a CodingKeys enum mapping the property back to the original JSON key, so decoding still works correctly.

What happens with nested objects and arrays?

A nested object becomes its own separate Codable struct, named after the field it appeared under. An array of objects reuses that same generated struct as its element type; an array of primitives becomes a plain Swift array like [String] or [Int].

What if a field is null in my sample?

A null value is generated as an optional String? since the real type can't be inferred from a single null sample — edit the generated type by hand once you know what the field actually holds.

How we compare

Feature Online Tool Store Xcode "Paste JSON as Code" Writing structs by hand
No Xcode required
Auto CodingKeys for snake_case

Type inference is based on a single JSON sample — always double-check optionality and numeric precision against your real API response before shipping.

Explore related tools

Embed this tool

Paste this on your own site — it stays free, and every file still stays in your visitor's browser, not yours or ours.