JSON to Swift

Generate Swift Codable structs or classes from JSON

JSON input

Options

Model
Type style
Serialization

Swift output

Paste JSON or load an example to generate Swift code.

What JSON to Swift generates

JSON to Swift turns an API response or any JSON sample into Swift types. Structs get the memberwise initializer for free; final classes get a generated init. When a property name differs from its key, for example user_name → userName, a CodingKeys enum maps every property back to the JSON. Reserved words such as class are escaped with backticks and keep their original name.

How to use
  1. 1.Paste JSON, upload or drop a .json file, or load one of the examples.
  2. 2.Set the root type name and choose the type style.
  3. 3.Choose the conformance and the CodingKeys policy (when names differ, always or never).
  4. 4.Read the notes under the output, then copy the code or download Models.swift.
How types are inferred
  • •Every array item is inspected, not just the first one, and objects in the same array are merged.
  • •A key missing from some objects is optional; a key that is sometimes null is nullable. The two are kept apart.
  • •1 and 2.5 in the same position widen to a decimal number; other mixes are reported.
  • •Empty arrays and values that are only ever null have no type evidence, so a generic type is used and a note explains why.
  • •Type mapping: string → String, integer → Int (UInt64 or Decimal beyond that), decimal → Double, boolean → Bool, array → [T], object → nested type, missing or null → T?, unknown or mixed → JSONValue (Any without conformance).
Limits and privacy

A sample shows what the data looked like once, not the full API contract. Review optional fields, generic types and number widths before relying on the code. Input is limited to 5 MB and 256 nesting levels; from 2 MB, generation waits for the Generate button. Everything runs in your browser and the JSON is never uploaded. If you choose to never write CodingKeys, renamed properties no longer match their JSON keys; the notes list each one.

CodingTool is officially live on

Launched on StartupBaseCodingTool.dev - Free, Fast & Easy Developer Tools in One Place | Product HuntCodingTool - Featured on Startup FameFazier badgeListed on Turbo0Featured on Twelve ToolsFeatured on Findly.toolsLaunchpadly Startup DirectoryCodingTool.dev — Featured on Smol Launch