MagmaNex LogoMagmaNex

JSON to Swift Struct

Generate Swift Codable structs from JSON

What does this tool do?

JSON to Swift turns your JSON into Swift structs that already conform to the Codable protocol. It's ideal for developers modeling an API response in an iOS, macOS, or server-side Swift app, and your data never leaves the browser.

How to use it

  1. Paste or type your data into the left field.
  2. The result is generated instantly on the right.
  3. Use the Copy button to grab the output.

Codable-ready output

Every generated struct conforms to Codable, and the file starts with import Foundation, so you can decode the output straight away with JSONDecoder. snake_case field names from the JSON are converted to the camelCase style Swift prefers. Whenever a name changes, the tool adds a CodingKeys enum inside the affected struct that maps back to the original JSON key, so encoding and decoding work without any extra wiring.

Type and nesting inference

The tool infers Swift types from the values: whole numbers become Int, decimals become Double, booleans become Bool, and text becomes String. Nested objects produce their own structs named after the field, and arrays become [T] based on the first element. null values are marked as the optional String?, and anything genuinely ambiguous falls back to Any so the model still covers the shape of your data.

Frequently asked questions

Can I set the root struct name?

Yes. Type your preferred name into the struct name field; the top-level struct uses it, while nested structs are generated automatically from their field names.

How are snake_case JSON keys mapped?

When a field is converted to camelCase, the tool adds a private enum CodingKeys inside the struct that maps the original snake_case key to the camelCase property.

How are null values represented?

null values are emitted as the optional String?, which decodes to nil when the value is absent.

Is JSON to Swift Struct free?

Yes. JSON to Swift Struct and all 300+ tools on MagmaNex are completely free with no signup or account required.

Is my data safe?

Yes. Everything runs locally in your browser. The data you enter is never sent to a server, stored, or shared.

Does it work on mobile?

Yes. JSON to Swift Struct works on phones, tablets and desktops — no app download needed.

🔒 Privacy: everything runs in your browser, your data is never sent to a server.

Related Tools

📝 Related Articles

Popular Tools