JSON to Swift
Paste or drop your data here, or open a file.
New to Bracely?
Everything stays in your browser.
Output appears here
Paste or open your data in the input box. It never leaves your browser.
JSON to Swift
Paste a JSON sample, such as an API response, and Bracely writes Swift Codable structs for it. Each object becomes a struct that conforms to Codable, with CodingKeys when a key isn't a valid Swift name.
Example: a weather forecast for an iOS app
A forecast response with a nested list of hours. Each object becomes a Codable struct, snake_case keys get CodingKeys so the properties can be camelCase, and the alert that only some hours have becomes an optional:
Input
{
"city": "Pune",
"updated_at": "2026-10-29T10:00:00Z",
"hours": [
{
"time": "10:00",
"temp_c": 27.5,
"rain_chance": 10
},
{
"time": "11:00",
"temp_c": 29,
"rain_chance": 40,
"alert": "Heavy rain expected"
}
]
}Output
import Foundation
struct Forecast: Codable {
let city: String
let updatedAt: String
let hours: [Hour]
enum CodingKeys: String, CodingKey {
case city
case updatedAt = "updated_at"
case hours
}
}
struct Hour: Codable {
let time: String
let tempC: Double
let rainChance: Int
let alert: String?
enum CodingKeys: String, CodingKey {
case time
case tempC = "temp_c"
case rainChance = "rain_chance"
case alert
}
}
How do I use the JSON to Swift?
- Paste a JSON sample.
- Set the root type name, for example Order.
- Copy the Swift code into your project.
What does the JSON to Swift do?
- Codable structs you can decode with JSONDecoder
- Optionals for fields that can be missing
- Arrays typed as [T]
- Nested objects become their own named types
- 20 other languages from the same sample, including TypeScript
When to use the JSON to Swift
iOS and macOS apps decode JSON with Codable and JSONDecoder. Writing the structs by hand, with CodingKeys for every snake_case key, is tedious; paste a real response, such as the forecast in the example, and copy structs that decode it as they are.
Each object becomes a struct conforming to Codable with let properties. When any key isn't camelCase, the struct gets a CodingKeys enum that maps updatedAt to "updated_at", so the Swift names follow Swift style. Whole numbers become Int, decimals and mixes of both Double, and a field missing from some items becomes an optional. Arrays are typed [T] with their own struct.
Frequently asked questions
- Can I use keyDecodingStrategy instead of CodingKeys?
- Yes. If every key is snake_case, set decoder.keyDecodingStrategy = .convertFromSnakeCase and delete the CodingKeys enums; the property names already match what it produces.
- Why are dates String?
- JSON has no date type, so a timestamp in the sample is text. Change the property to Date and set decoder.dateDecodingStrategy = .iso8601 to have JSONDecoder parse it.
- How does it pick Swift types?
- From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
- Can I generate other languages?
- Yes. Change Language to any of the others: TypeScript, Go, Python, Pydantic, Java, C#, Kotlin, Rust, Scala, Ruby, Dart, PHP, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
- Is my data uploaded?
- No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.
More JSON tools
Bracely has 108 JSON tools in one page. Related ones:
- JSON to Dart
- JSON to Rust
- JSON to PHP
- JSON to Zod
- JSON to GraphQL
- JSON to Protobuf
- JSON to Pydantic
- JSON to TypeBox
- JSON to Valibot
- JSON to Yup
- JSON to Prisma
- JSON to Drizzle
- JSON to Scala
- JSON to Ruby
- cURL to JSON
- Postman collection viewer
- Password generator
- Mock JSON generator
- HTML formatter
- CSS formatter
- JSON Formatter
- JSON Validator
- JSON Viewer
- JSON Repair
- JSON Diff
- JSON to YAML
- JSON to CSV
- jq Playground
Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram