JSON to Swift Codable Generator
Convert JSON to Swift Codable structs or classes online with CodingKeys, optionals and nested types. Ready for JSONDecoder β free, instant and private in your browser.
π Runs entirely in your browser β nothing is uploadedSwift Codable models from JSON
Swift's Codable protocol turns JSON decoding into a single line β once you have types that match the payload exactly. This JSON to Swift converter generates those types from a sample. Each object becomes a struct (or class) conforming to Codable, keys become camelCase properties, nested objects become their own types, arrays become typed Swift arrays, and values that are missing or null in part of the sample become optionals. Explicit CodingKeys enums map each property back to the original JSON key, so snake_case APIs decode without any custom strategy.
The engine behind it is quicktype, which merges all elements of every array before inferring types. A field that appears in only some items still becomes an optional property, avoiding the dreaded keyNotFound decoding error at runtime.
Structs, classes and helpers
Structs are the default because value types are idiomatic for models in SwiftUI and most modern iOS and macOS code. Switch to classes when you need reference semantics or Objective-C interop. By default the output also contains convenience helpers β initialisers from JSON data and strings, jsonData() and jsonString() methods, and a with(...) mutator β which make the models easy to use in tests and previews. Tick Types only if you prefer a minimal file with nothing but the Codable declarations.
Tips before you paste into Xcode
Use a rich sample with several array items and optional fields filled in. Rename the root type from Root to something meaningful like FeedResponse; the download will use that name. Afterwards, consider turning string fields with known values into enums, using Date with a matching dateDecodingStrategy, and marking properties var where you need mutation. Everything happens locally in your browser, so private API responses are never uploaded.
How to use
- Paste JSONPaste a JSON response or load the sample.
- Choose the stylePick struct or class, CodingKeys and whether to include helpers.
- Copy into XcodeCopy the Swift code or download a .swift file for your project.
Frequently asked questions
Are the generated types Codable?
Codable, so you can decode it with JSONDecoder straight away.What are explicit CodingKeys for?
Can I generate classes instead of structs?
class if you need reference semantics, for example for Core Data or Objective-C interop.