One document, or several samples as JSON Lines.
Options for Swift

No options for Swift; the name above is the root type.

Convert JSON to Swift Codable structs

Paste a JSON sample and get Swift structs conforming to Codable: String, Int, Double, Bool, [T] arrays, nested structs, optionals for fields that are null or missing in some records, and a CodingKeys enum whenever a key isn't a camelCase Swift name.

Decode with JSONDecoder().decode(Root.self, from: data). It runs entirely in your browser.

Need a different language? See all JSON-to-code converters.

JSON to Swift Codable Struct Converter — frequently asked questions

What is AnyCodable in the output?
A field whose values have no single type (a string in one record, a number in another) is typed AnyCodable, a small wrapper you can write or take from the AnyCodable package. The output says so when it needs it.
What if some records have fields that others don't?
Every item of every array and every sample is read, not just the first. A field missing from some records comes out optional, a field holding two kinds of value becomes a union (or the language's any-value type), null beside a value makes it nullable, and a list of records at the top level gets an item type plus an alias for the list. Paste several samples as JSON Lines, one per line, and they're merged the same way.
Is my JSON uploaded anywhere?
No. Parsing and code generation run entirely in your browser with JavaScript — your JSON never leaves your device, so it's safe to paste API responses and other sensitive payloads. It's free with no sign-up.

Spotted a bug or have a suggestion?

Found something broken, have an idea, or just want to say thanks about any of our tools? Every message reaches a real person.