JSON to Swift Converter
Convert JSON to Swift Codable structs online. Generates camelCase properties, CodingKeys for snake_case keys and optionals — all in your browser.
What is the JSON to Swift Converter?
The ByteTools JSON to Swift Converter generates Codable structs from a sample JSON document. Properties are renamed to Swift-style camelCase, and when the JSON uses snake_case or other non-matching keys a CodingKeys enum is generated automatically so encoding and decoding still line up with the original payload.
- Codable structs ready for JSONDecoder
- CodingKeys enum generated only when keys need mapping
- Optionals for null values and keys missing from some elements
- Nested structs named from their JSON keys
- let or var properties with one toggle
- 100% private — JSON never leaves your browser
How to use the JSON to Swift Converter
- 1
Paste a JSON sample into the input box.
- 2
Set the root struct name and optionally switch to var properties.
- 3
Click Generate Swift to build the Codable structs.
- 4
Copy the code or download it as a .swift file.
About the JSON to Swift Converter
The ByteTools JSON to Swift Converter generates Codable structs from a sample JSON document. Properties are renamed to Swift-style camelCase, and when the JSON uses snake_case or other non-matching keys a CodingKeys enum is generated automatically so encoding and decoding still line up with the original payload.
It is designed for iOS and macOS developers modeling an API response. Arrays become Swift arrays like [Post], nested objects become their own structs named from their keys, values that are null or missing in parts of the sample become optionals, and you can switch between let and var properties.
The conversion runs 100% locally in your browser. Your JSON is never uploaded or stored, so you can safely paste private API responses. Fields with mixed or null-only values are flagged with an honest inline comment instead of silently guessing.
Frequently asked questions
How do I convert JSON to Swift structs?
Paste a representative JSON sample, name the root struct and click Generate Swift. The tool infers each property's type, creates nested structs for nested objects and outputs Codable code you can decode with JSONDecoder immediately.
When is a CodingKeys enum generated?
Only when at least one JSON key differs from its Swift property name — for example user_name becoming userName. If every key already matches, the enum is omitted to keep the struct clean, since Codable synthesizes the keys automatically.
How does it decide between Int and Double?
If every value of a field in the sample is a whole number the property is Int; if any value has a decimal point it becomes Double. Booleans map to Bool and text to String.
What happens with mixed-type or always-null fields?
Swift's Codable has no built-in any-type, so the tool uses a String placeholder and adds a NOTE comment telling you exactly which field to review. That is more honest than generating code that silently mistypes your data.
Is my JSON uploaded anywhere?
No. Generation happens entirely in your browser with JavaScript, so confidential payloads never leave your machine.
Related tools
JSON to Kotlin Converter
Convert JSON to Kotlin data classes online with kotlinx.serialization or Gson annotations, nullable types and List<T> — 100% in your browser.
JSON to Dart Converter
Convert JSON to null-safe Dart classes online, with generated fromJson and toJson methods, typed List<T> fields and nested classes — in your browser.
JSON to TypeScript
Generate TypeScript interfaces from a JSON sample online. Infers types recursively, merges array shapes and marks optional keys — 100% in your browser.
JSON Validator
Free online JSON validator: validate JSON and find syntax errors with the exact line and column. See root type, key counts and depth — instant and 100% private.
JSON Viewer
View JSON as a collapsible interactive tree online. Expand and collapse nodes, search keys and values, and copy the JSONPath of any node privately.