Why use this generator
Codable conformance
Every struct conforms to Codable out of the box. Works directly with JSONDecoder and JSONEncoder.
CodingKeys
When a JSON key isn't a valid Swift identifier or doesn't match Swift's camelCase convention, a CodingKeys enum maps the property name to the JSON key.
Type mapping
JSON strings become String, integers become Int, floats become Double, booleans become Bool, null becomes Any?. Arrays become [T].
Conversion explained
1. Parse JSON
Input is parsed into a JavaScript value. The struct structure is determined by walking the value tree.
2. Collect structs
For each object, a Swift struct is generated with let properties and Codable conformance.
3. Emit Swift
Structs are emitted with proper Swift formatting: struct keyword, let properties, CodingKeys enum when needed.
JSON to Swift Codable Struct Generator — frequently asked questions
Is this compatible with JSONDecoder?
Yes — the generated structs conform to Codable, so they work directly with JSONDecoder.
Why use Double instead of Float?
JSON numbers are 64-bit doubles by default. Double matches this precision exactly. If you need the memory savings, edit the output to use Float.
How are optional fields handled?
Currently, all fields are required (non-optional). For optional fields, edit the output to use T? (e.g., String?, Int?).
Can I customize the property names?
Yes — by default, JSONLab uses the JSON key as the Swift property name. If the key isn't a valid Swift identifier, it's sanitized and a CodingKeys enum maps back to the original.
You might also like
JSON to Kotlin
Generate Kotlin data classes from JSON
JSON to Java
Generate Java POJO classes from JSON
JSON to Python
Generate Python dataclasses from JSON
JSON to Go
Generate Go structs from JSON
JSON to TypeScript
Generate TypeScript interfaces from JSON
JSON Validator
Validate JSON syntax with detailed error messages