JSON to Swift
Paste a JSON sample and get Codable Swift structs with nested types, optionals and ready made CodingKeys.
Generate Codable structs from JSON
Structs: 0 · Properties: 0 · Lines: 0
Paste a JSON object or array and press Generate Swift.
How to use the JSON to Swift
- Paste a JSON object or array into the sample box, or press Load sample to try one.
- Set the root struct name and choose how optionals should be handled.
- Press Generate Swift and copy the structs, then decode with JSONDecoder in your app.
Features
- Infers Codable structs with nested types and arrays of objects
- Optionals added for values that are null in the sample
- CodingKeys enums built for keys that are not valid Swift names
- Includes the JSONDecoder call in a comment under the code
Advertisement
Frequently Asked Questions
Common questions about the free online json to swift.
Paste a JSON sample, set the root struct name and press Generate Swift to get Codable structs
you can paste into Xcode.
Yes. Nested JSON objects and arrays of objects each become their own struct, named after the
key that holds them.
A property becomes optional when the sample value is null, or when array elements disagree
about the key.
If a JSON key is snake case or not a valid Swift name, a CodingKeys enum maps the Swift
property to the original key.
Numbers become Double, true and false become Bool, text becomes String, arrays become Swift
arrays and objects become structs.
Use JSONDecoder and decode the root type, as shown in the comment at the end of the generated
code.
The sample alone cannot tell an integer from a decimal, so Double is used and you can change
it to Int where you know better.
An empty array gives an array of String, which you can change once you know what the elements
really are.
Yes. It is free, runs entirely in your browser and never sends your JSON sample to a server.
Last updated: October 10, 2026