JSON to Swift Converter
Generate Swift Codable models and CodingKeys from JSON samples. Infer nested structs and optional values without uploading your input.
How to generate Swift models
Use a name such as CatalogResponse for the root struct. Review nested Swift models and check CodingKeys if the API uses JSON names different from your Swift properties.
Complete output uses Foundation and Codable, including decoding/encoding helpers and CodingKeys for renamed fields. Add the Swift file to your project; no third-party serialization library is required. Models-only mode creates plain structs and omits Codable support. Standard Codable encoding omits nil properties, so an explicit null may serialize as a missing field.
Samples, optional fields and limits
Keep strings as strings when preparing Swift samples, even for IDs, dates and UUIDs. Treat the result as a model inferred from examples. Limits are 200,000 input characters, 64 nesting levels, 50 samples, 50 files and 1,000,000 output characters. The local worker can be cancelled and has a 10-second deadline.
Questions & answers
How should I sample missing and null fields for Swift?
Include omitted keys and explicit nulls in JSON Lines samples. Review where the result uses Swift optionals and test your own round trip if the distinction matters when encoding.
Does the page run Foundation or send the samples to Swift?
The generator reads JSON and writes Swift source in the browser. The Codable helpers run only after you add them to a Swift project and execute them there.
Other Languages
References
How we make sure
We check this tool with the automated test suites linked below. Example checks are shown in their original language.
- Verification method
- When swiftc is installed, compile generated Codable models and round-trip original JSON names; otherwise check declarations only.
- Comparison reference
- Swift compiler and Codable execution; requires a local Swift environment.
- Verification scope
- These samples and boundaries do not prove correctness for every input.
Test source and cases (select a file to read it)
-
code-tools.test.js
- JSON to Swift Codable compiles and round-trips fields with their original JSON names
These checks cover the listed examples and boundaries, not every possible input. Round trips and checks using the same library are not independent verification.