{ }jsonkit
Format
Validate
Convert
Query
Generate
→swift

JSON to Swift Codable Struct Generator

Generate Codable structs, optionals, arrays and CodingKeys.
353 B · paste or drop a file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
✓ complete353 B → 2162 B0.0 ms

About JSON to Swift

The JSON to Swift generator builds nested structs from a representative JSON response. It maps objects to structs, arrays to typed Swift arrays, strings to String, booleans to Bool and numeric samples to Int or Double, adding optionals for null or missing values.

Codable mode makes the models ready for JSONEncoder and JSONDecoder and emits CodingKeys when a Swift-safe camelCase property differs from the original wire key. Choose let properties for immutable response models or var properties when your application needs to edit decoded values.

All inference happens in your browser, so private mobile API payloads and customer records are not transmitted. Treat the result as a scaffold: JSON samples cannot prove date formats, enum cases, decimal precision, optionality outside the sample or polymorphic response rules.

How it works

Generate Swift structs recursively

A root object becomes Root and each nested object receives a readable type name based on its key. Arrays of objects are merged into one element struct, retaining keys seen anywhere in the sample and making partially present members optional.

Create Codable and CodingKeys

Codable mode adds Codable conformance. When names such as user_id or created-at are converted to Swift properties, a CodingKeys enum maps the clean identifier back to the exact JSON key for correct encoding and decoding.

Infer optionals and numeric types

Null values and keys missing from some array elements receive a question mark. Whole numbers become Int and decimals become Double. If an endpoint can exceed the platform Int range or requires exact money arithmetic, replace the inferred type with Int64 or Decimal.

Choose immutable or mutable properties

The default let output is a good fit for decoded API response values and predictable state flow. Enable mutable properties to emit var when the same model will be edited before display, persistence or re-encoding.

Frequently asked questions

Will the generated Swift models decode immediately?

Homogeneous, fully represented samples normally produce ready-to-use Codable structs. Empty or heterogeneous arrays may require a manual concrete type, and API-specific date or polymorphic decoding still needs a decoder strategy or custom implementation.

Why is a property optional?

The value was null or the key was absent in at least one object from a sampled array. The generator cannot discover optional keys that never go missing in your sample, so verify them against the endpoint documentation.

Does it recognize ISO 8601 dates automatically?

No. JSON represents dates as strings, and matching a date-looking pattern can be misleading. The output keeps String so you can deliberately select Date, configure JSONDecoder.dateDecodingStrategy or preserve the original text.

Is the pasted JSON private?

Yes. The sample is parsed and converted locally in your browser and is not uploaded by the generator.