Zero Signup ToolsFree browser tools

Developer Tools

JSON to Swift Converter

Convert JSON to Swift Codable structs, classes, or Decodable types in your browser. CodingKeys, nested types, optional inference, and copy-paste output.

0 chars

Output options

Live preview updates with every change. Parsing and inference run in your browser; the JSON you paste is not uploaded.

Used as the name of the top-level type. Normalised to a valid UpperCamelCase Swift identifier automatically.

Output style

struct is the Swift API guideline default for plain data transfer objects. class is useful when you need reference semantics or compatibility with NSObject hierarchies. Decodable only is right for one-way API responses you never encode back.

Number type

Double is faster and matches what most JSON APIs return. Pick Decimal for currency, billing, or scientific values where binary floating-point error would be unacceptable.

Property mutability

let is the Swift convention for decoded payloads. Use var only when downstream code needs to mutate fields in place.

Indent

Xcode and the official Swift formatter default to 4 spaces. Choose 2 if your project already uses it.

How to use

  1. Paste a JSON value into the input area, or click Load sample to start with a typical nested object payload.
  2. Set the root type name (the top-level struct or class), which is normalised to a valid UpperCamelCase Swift identifier automatically.
  3. Pick an output style: struct + Codable for plain DTOs, class + Codable for reference semantics, or Decodable only for read-only API responses.
  4. Choose Double or Decimal for fractional numbers, set 2 or 4 space indentation, and toggle public access, let vs. var, and optional handling to match your project.
  5. Read the type count and JSONValue notice in the result header, then click Copy Swift to paste the generated model into your Xcode project.

About this tool

JSON to Swift Converter takes any JSON value (API response, fixture, payload exported from Postman) and turns it into a clean Swift model file that compiles with the standard JSONDecoder and JSONEncoder out of the box. Numbers are split into Int and Double (or Decimal when you need exact decimal arithmetic for currency and billing), booleans become Bool, strings become String, JSON null produces an Optional, arrays become [T], and nested objects are promoted into their own named types so the model stays flat and readable. Repeated occurrences of the same shape across an array are merged, so a field that is present in some elements and missing in others is correctly marked Optional in the generated property. JSON keys that do not match the Swift naming convention (snake_case, kebab-case, leading numbers, reserved words) are renamed to lowerCamelCase Swift properties and a CodingKeys enum maps them back to the original wire spelling, so Codable round-trips the payload exactly. Three output styles cover the common iOS and macOS use cases: struct + Codable for value-type DTOs (the Swift API guidelines default), final class + Codable for reference semantics or Cocoa interop with an explicit memberwise initializer, and Decodable only for one-way API responses you never re-encode. You can choose 2 or 4 space indentation to match your project, switch to a public access level when the model ships from a Swift package, mark properties as let or var, and alphabetize properties when you want a deterministic declaration order. Mixed-type and unknown fields are decoded through a lightweight JSONValue helper that is appended only when the source actually needs it, so the output stays compile-clean even with messy real-world JSON. Everything runs in your browser, so API keys, internal payloads, customer fixtures, and JWT samples you paste here never leave your device.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools