JSON to Swift Codable Generator

Generate Swift Codable structs with CodingKeys from JSON samples.

  • 100% client-side · your data never leaves your browser
  • Instant, no rate limits
  • Free, no sign-up
Input JSON
Swift structs

Your result appears here

Paste JSON into the panel on the left — everything runs privately in your browser.

Overview

JSON to Swift Codable Generator — Structs Online

Generate Swift Codable structs from a JSON sample for your iOS, macOS, or server-side Swift app. JsonDrift infers property types, emits nested structs, and adds a CodingKeys enum whenever a property name differs from the JSON key — so JSONDecoder maps everything correctly. Private and client-side.

No uploadsNo sign-upOpen source
  1. Why generate Codable structs from JSON?

    Swift's Codable makes JSON decoding type-safe, but you still have to declare the structs. Writing them by hand for a nested API response is slow and easy to get wrong. Generating from a real payload gives you a correct set of Codable types you can decode immediately with JSONDecoder.

  2. What gets generated

    Objects become structs conforming to Codable; nested objects become their own structs. Strings map to String, whole numbers to Int, decimals to Double, booleans to Bool, and arrays to [T]. Property names are camelCased, and when a name differs from the JSON key a CodingKeys enum is emitted to map it.

    • String, Int, Double, Bool, [T]
    • Nested objects become nested Codable structs
    • CodingKeys enum for keys that don't match property names
    • import Foundation header included
  3. Decoding with JSONDecoder

    Paste the structs into your project and decode with try JSONDecoder().decode(Root.self, from: data). If your API uses snake_case keys, you can either keep the generated CodingKeys or set decoder.keyDecodingStrategy = .convertFromSnakeCase and drop them — both approaches work.

  4. Review before shipping

    Generated structs mirror one sample. Mark fields that may be absent as optional (T?), use Date with a dateDecodingStrategy for timestamps, and double-check numeric types — an id that arrives as a large integer may need Int64. Treat the output as a starting point you refine.

FAQ

Frequently asked questions

How do I convert JSON to Swift structs?

Paste a JSON sample and JsonDrift generates Codable structs with the correct types and CodingKeys, ready for JSONDecoder.

Does it add CodingKeys?

Yes. When a camelCased property name differs from the JSON key, a CodingKeys enum is emitted so decoding maps back to the original keys.

Are the structs Codable?

Yes. Every generated struct conforms to Codable, so it works with both JSONDecoder and JSONEncoder.

Is my JSON uploaded?

No. Generation runs entirely in your browser.

Continue with a related tool

All tools

Learn more in our guides

All guides