Swift to JSON Converter

Paste Swift structs or Codable types. Get clean JSON back.

Input

Output

Paste your Swift code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

You made a Swift struct Codable, and now you only want to see the JSON it encodes to. Opening a playground, building a JSONEncoder and printing the Data as a String is a lot of ceremony for that. Paste the type and an instance here and read the JSON off the right panel, no Xcode or Swift Package Manager involved. One instance, a file of models, or nested arrays and optionals all come back as one document.

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

No simulator and no Xcode project: paste one instance or a whole Models.swift and the steps are the same.

1

Paste your Swift (or load the sample)

Paste the Swift into the left editor with its import Foundation and CodingKeys intact. A struct, a class, an enum with associated values, several types or nested arrays and dictionaries all work. Load Sample loads an Order whose CodingKeys map orderId to order_id.

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

2

Hit Convert

Press Convert. The code is posted to the backend, which applies your CodingKeys renames, turns nil into null and returns the JSON. The "Converting..." overlay stays up until the result is back. Nothing is compiled, so a module you have not imported will not stop it.

3

Copy the JSON

Your JSON shows up in the right editor. Paste it into a URLProtocol stub, a snapshot test, the example section of an OpenAPI file, or the body tab of Proxyman or Postman.

When this actually comes in handy

iOS API fixtures

You are wiring up a URLSession POST and the backend team wants to see the body before they build the endpoint. Paste the request struct with realistic values and send them the JSON.

Mock server responses

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

Vapor / SwiftNIO backend tests

A Vapor service with 20 Content 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?

Swift source sent here goes to the backend only to be converted; it is not saved and the payload is not logged. Check your Config.swift for hard-coded tokens 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

Working across platforms? The Kotlin and C# converters handle the Android and .NET side of the same models: