CODDY Tool

JSON to Swift

Turn a JSON sample into Swift type definitions.

Paste a JSON response and get Swift types back. Every element of an array is merged, so fields missing from some objects come out optional rather than required.

Everything you enter stays in this browser tab. Nothing is sent to our servers, logged or stored.

This is one of the thingsJSON Type Generatordoes — open it for everything else it supports.

Loading tool…

What JSON Type Generator supports

  • TypeScriptExported interfaces.
  • GoStructs with json tags.
  • KotlinData classes.
  • SwiftCodable structs.
  • PythonDataclasses.
  • C#Classes with properties.

About JSON to Swift

Swift's Codable protocol turns a struct into a JSON decoder with no extra code, provided the struct actually matches the data. When it does not, decoding throws rather than degrading, so accuracy matters more here than in a dynamically typed language.

Fields missing from some array elements are emitted as optionals, which is what stops decoding failing on a response that omits them.

Where a JSON key is not a valid Swift property name it is camel-cased, and a CodingKeys enum is generated to map every property back to its original key. Without that enum the renamed property simply never decodes.

How to generate Swift types

  1. Paste your JSON

    A whole array is better than one object — more samples means a more accurate type.

  2. Name the root type

    Nested objects are named automatically from the keys that hold them.

  3. Copy the definitions

    Types are emitted children first, so the file compiles in order.

Frequently asked questions

Why is a field optional when my sample has it?

Because at least one object in the array you pasted was missing it. That is a real difference in the data, and a type that marks it required would compile and then fail at runtime on the object that lacks it.

Why did a field come out as unknown?

Because the same key held genuinely different types across your samples — a number in one object and a string in another. There is no single type that describes both, so widening to unknown is the honest answer.

Does it handle nested objects?

Yes. Each nested object becomes its own named interface, named after the key holding it, and a key holding an array is singularised — users produces a User rather than a Users.

Is my JSON uploaded anywhere?

No. Everything is parsed and generated in this browser tab, which matters when the sample is a response from an unreleased API.

All Developer Tools

JSON to Swift is free to use with no account, no watermark and no usage limits. Last updated 14 August 2026.