Paste Swift on the left and click "Convert" — we will turn it into JSONPaste Swift code

What this tool does

If you have ever defined a Swift struct, made it Codable, and realized you just need the JSON without spinning up a playground or a simulator — this tool does that. Paste the Swift here and get valid JSON back without touching JSONEncoder, Xcode, or the Swift Package Manager. It handles a single struct instance, a whole file with several types, or something with nested arrays and optionals — same result: a clean JSON document with every property preserved.

The converter tracks how Swift values actually serialize through JSONEncoder. String, Int, Double, Bool map to their obvious JSON counterparts. [Item] arrays become JSON arrays; [String: V] dictionaries become JSON objects. Optional<T> with nil becomes JSON null (or is omitted, depending on the encoder strategy). UUID becomes a standard hex string, Date becomes an ISO-8601 string, and URL becomes a string. Enums with raw values emit the raw value — the same behaviour you get with Foundation.JSONEncoder.

Custom CodingKeys are respected — if you rename a property for JSON (case shippingAddress = "shipping_address"), the output uses the renamed key. Nested Codable types expand inline. Paste several structs at once and each becomes a top-level entry in the output. If you want to dig deeper into how Swift models JSON, apple/swift has the source, and Hacking with Swift has readable explainers for the Codable protocol.

How to use it

Three steps. Works the same whether you paste one struct instance or a full model file.

1

Paste your Swift (or load the sample)

Drop your Swift into the left editor as-is. A struct, a class, an enum with associated values, multiple types, or nested arrays and dictionaries — all fine. Click Load Sample to see a realistic example first.

You do not need to remove import Foundation or @available attributes. Leave the Swift syntax intact — the parser handles it.

2

Hit Convert

Click the green Convert button. The tool reads the Swift, preserves every property and nested type, and emits the JSON in one pass. A short loading indicator runs while it works.

3

Copy the JSON

The right panel fills with indented JSON. Copy it into your URLSession test, a MockURLProtocol fixture, your OpenAPI examples, or a REST client. That is the whole loop.

When this actually comes in handy

iOS API fixtures

You have a request struct for a <code>URLSession</code> call and need a JSON payload for Postman or a test. Paste the struct, grab the JSON, move on.

Mock server responses

Turn your response <code>Codable</code> types into JSON you can drop into a mock server, <code>MockURLProtocol</code>, or a recorded-response file — no <code>JSONEncoder</code> call required.

Vapor / SwiftNIO backend tests

A Vapor service with 20 <code>Content</code> types. Generate JSON seed files for integration tests without writing a single encode call.

Docs and OpenAPI examples

Generate JSON examples for your OpenAPI spec or API reference straight from your actual models, so docs stay in sync.

Common questions

Does the type need to conform to Codable?

The type does not need to actually conform in your code for the tool to work — the converter reads the shape and produces the JSON directly. In your own app, Codable (or at least Encodable) is how you get the same result at runtime through JSONEncoder.

Does it honour custom CodingKeys?

Yes. If your type defines enum CodingKeys: String, CodingKey with custom raw values (case shippingAddress = "shipping_address"), the output uses those renamed keys.

How are Optionals, Dates, and UUIDs handled?

Optional<T> with nil becomes JSON null. Date comes out as an ISO-8601 string by default (matching JSONEncoder.DateEncodingStrategy.iso8601). UUID becomes a standard hex string. URL becomes a string.

What about enums with associated values?

Enums with raw values emit the raw value directly. Enums with associated values come out as a tagged object — the same shape Swift itself produces when you encode a case with associated values.

Is my code stored?

Your code is sent to the backend for conversion and is not persisted — we do not log the payload. Give sensitive code a review before pasting.

Does it work for SwiftUI models and property wrappers?

Yes — property wrappers like @Published are unwrapped to their inner value. ObservableObject classes with @Published properties serialize cleanly. SwiftUI-specific view types are not serializable data, but any model behind your views is fair game.

Other tools you may need

Swift to JSON is one piece of the puzzle. These pair well with it: