{ JSON to Swift Struct }

// generate codable swift structs from json instantly

Convert JSON to Swift Codable structs instantly. Generate clean, type-safe Swift models for iOS and macOS development with optional properties and nested support.

🦅

Swift struct will appear here

Paste JSON and click Generate

HOW TO USE

  1. 01
    Paste JSON

    Paste any valid JSON object or array of objects into the input panel.

  2. 02
    Set Options

    Choose a root struct name and toggle options like public access or Foundation import.

  3. 03
    Generate & Copy

    Click Generate to produce Codable Swift structs. Copy or download the .swift file.

FEATURES

Codable Nested Structs CodingKeys Arrays Optional Support iOS & macOS

USE CASES

  • 📱 Parse REST API responses in Swift
  • 🏗 Scaffold models for new iOS projects
  • 🔄 Convert backend JSON schemas to Swift
  • 🛠 Rapid prototyping for Xcode projects
  • 📦 Generate data models for SwiftUI

WHAT IS THIS?

This tool generates Swift Codable structs from JSON input, automating the tedious task of writing model types for iOS and macOS. Paste your API response JSON and get production-ready Swift code in seconds.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

What is a Codable struct in Swift?

Codable is a Swift type alias for Encodable & Decodable. When a struct conforms to Codable, Swift can automatically encode it to JSON and decode JSON into it — no manual mapping needed.

Does the tool handle nested JSON objects?

Yes. Any nested JSON object becomes its own separate Swift struct. The parent struct references the child by name, and all nested structs are output together so you can paste them directly into Xcode.

How are JSON keys with underscores handled?

JSON keys like first_name are automatically converted to Swift-style camelCase properties (firstName). A CodingKeys enum is generated to bridge the original JSON key to the Swift property name.

Can I use the output with URLSession?

Absolutely. The generated structs are standard Codable Swift types. Pass them to JSONDecoder().decode(Root.self, from: data) in any URLSession completion handler or async/await networking code.

Are optional properties supported?

Yes. If a JSON value is null, the corresponding Swift property is generated as an Optional (e.g., String?). For robust API parsing you can also manually add ? to any property you expect might be missing.

What Swift types are generated?

JSON booleans → Bool, integers → Int, floats → Double, strings → String, arrays → typed arrays like [String] or [ChildStruct], nested objects → named structs.

Does this work for SwiftUI apps?

Yes. The generated structs are plain value types that work perfectly as SwiftUI data models. Add @Observable or wrap them in an ObservableObject class if you need state management.

Is my JSON data sent to a server?

No. All processing happens locally in your browser via JavaScript. Your JSON never leaves your machine, making this tool safe for sensitive API schemas and proprietary data structures.

JSON to Swift Struct Generator — Instant Codable Models for iOS & macOS

Writing Swift data models by hand is one of the most repetitive tasks in iOS development. Every time you integrate a new API endpoint, you need to inspect the JSON response, map each key to a Swift property, infer types, handle nested objects, and write a CodingKeys enum whenever the server uses snake_case. This JSON to Swift Struct Generator automates all of that in a single click.

💡 Looking for premium iOS and Swift UI kits? MonsterONE offers unlimited downloads of app templates, UI components, and Swift design assets — worth checking out.

What Does the Tool Generate?

Paste any valid JSON object and the generator produces Swift structs that conform to the Codable protocol. Each key in your JSON becomes a typed Swift property. Nested objects become their own named structs. Arrays are typed correctly — [String], [Int], or [ChildStruct] depending on the contents. If a value is null, the property is marked optional with a ? suffix.

When JSON keys use snake_case or other non-camelCase conventions, the generator automatically creates a CodingKeys enum that maps the original JSON key to a proper Swift property name. This follows Swift's official API Design Guidelines, which call for camelCase property names.

Understanding Codable in Swift

Introduced in Swift 4, Codable is a type alias combining the Encodable and Decodable protocols. When a type conforms to Codable, the Swift compiler synthesizes the encoding and decoding logic automatically — as long as all stored properties are themselves Codable.

This means you can decode a JSON response from a URLSession request with just two lines:

let decoder = JSONDecoder()
let result = try decoder.decode(Root.self, from: data)

No third-party libraries. No custom parsing logic. No fragile string subscripts. Codable is the modern, recommended way to handle JSON in Swift across all Apple platforms.

Using the Generated Structs in Xcode

Once you generate your structs, you can paste them into a new .swift file in Xcode. If you enabled the import Foundation option, the import statement is already included. Rename the root struct to match your domain model, adjust any property types if needed, and start decoding immediately.

For SwiftUI projects, the structs work as @State values or inside ObservableObject classes. For UIKit apps, they integrate seamlessly with any data layer, whether you're using MVVM, Combine, or async/await with structured concurrency.

Handling Complex JSON Structures

Real-world API responses are rarely flat. They contain nested objects, arrays of objects, nullable fields, and mixed-type arrays. Here is how the generator handles each case:

Swift Type Mapping Reference

Understanding how JSON types map to Swift types helps you verify and tweak the generated output:

Best Practices After Generating

The generated code is a solid starting point, but real-world models often need a few tweaks. Consider these refinements after generating your structs:

Why Use a Generator Instead of JSONDecoder keyDecodingStrategy?

JSONDecoder has a built-in .convertFromSnakeCase key decoding strategy that handles snake_case conversion automatically. However, explicit CodingKeys enums are often preferred in production code because they make the JSON contract explicit and visible, they survive refactoring without silent breakage, and they allow per-property customization beyond simple case conversion. This generator gives you the explicit version, which is safer for long-lived production codebases.

Compatibility

The generated Swift structs are compatible with Swift 5.5+ and work on iOS 13+, macOS 10.15+, watchOS 6+, tvOS 13+, and visionOS 1+. The Codable protocol has been stable since Swift 4, so the output is broadly compatible across Xcode versions and Apple developer toolchains.