How to convert JSON to Swift
- Paste a JSON object or array, for example a response from the API you are calling.
- Set the name of the root type.
- Copy the generated Swift code into your project.
What you get
- Structs that conform to
Codable, one per object. - camelCase properties plus a
CodingKeysenum only when some key needs renaming. - Optionals for missing or null values, and a small
JSONValueenum when a value has no single type.
Tips for accurate results
The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.
Frequently asked questions
Is my JSON sent to a server?
No. The code is generated in your browser, so API responses and other private data never leave your device.
How do I decode the JSON?
Use try JSONDecoder().decode(Root.self, from: data). The CodingKeys enum maps renamed properties back to their JSON keys.
What is the JSONValue type?
Swift has no built-in Codable type for arbitrary JSON. When a value is mixed or always null, the generator adds a small JSONValue enum that can hold any JSON value.
Should I use convertFromSnakeCase instead of CodingKeys?
You can set decoder.keyDecodingStrategy = .convertFromSnakeCase for snake_case APIs, but explicit CodingKeys also handle keys like "first-name" that no strategy converts.