TypeScript to XML Converter

Paste a TypeScript interface, type, or typed object. Get clean XML back.

Input

Output

Paste your TypeScript code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

Front-end and Node developers meet XML more often than they would like: a payment provider's SOAP API, an RSS or sitemap generator, a contract test against a Java service. The browser's XMLSerializer only works on a DOM you have already built, and it does nothing with a typed object. Paste your TypeScript interfaces together with a const order: Order = { ... }, press Convert, and our backend answers with an XML document built from the object's values and shaped by its types.

The converter reads the types, not just the values. interface Order { ... } + const order: Order = { ... } produces an <Order> root with every field from the interface. Optional fields (field?: T) that are missing from the literal become empty elements so the output matches the declared shape. readonly is ignored for output purposes. Enums emit their value (string enums emit the string, numeric enums emit the number). Union types emit whatever the actual literal contains. Generics are resolved by the concrete instantiation.

Type annotations themselves vanish, since they do not exist at runtime, but the structure they describe stays. A field typed OrderItem[] gets an <items> wrapper with an element per array entry. null and an optional field left undefined both become empty elements. A Date is written with toISOString() formatting and a bigint as its digits without the n. Record<string, V> is written as a list of <Entry> elements, each with a <Key> and a <Value>. Paste interfaces with no value and you get a template where strings are empty, numbers 0 and booleans false.

How to use it

Load Sample, Convert, then copy the result. What each step does with a types.ts paste:

1

Paste your TypeScript (or try the sample)

Paste the TypeScript into the left editor; import and export lines can stay. Load Sample gives you three interfaces (OrderItem, Address, Order) and a typed const order with two line items, which is the combination that produces filled-in values.

Keep the type annotations in: that is what the parser uses to decide output element names and types. Leave import and export statements too; they are ignored automatically.

2

Hit Convert

Press the green Convert button. Your TypeScript travels to our backend, which matches the object literal against its interfaces and returns the XML. Nothing is transpiled or executed, and a "Converting..." overlay sits over the editors meanwhile.

3

Copy the XML

The right pane holds the XML, indented by two spaces. Run it through new DOMParser().parseFromString(xml, "application/xml") in a test and check for a parsererror node, since that is how browsers report a document their XML parser rejects, then use it as your mock response or fixture.

When this actually comes in handy

SOAP / XML API clients

You have a TypeScript interface for a SOAP request body and need the XML skeleton to send over fetch. Paste the interface plus a typed example, copy the XML, paste it into your request.

XSD-driven contracts

Generate XML examples from your TS types for documentation that sits alongside an XSD. Keeps your examples in sync with the types, which are in sync with the schema.

Starting config files

A Settings interface with 40 fields becomes a ready-to-edit XML template for any XML-based config store. No handwritten element building, no typos, no forgotten fields.

Mock data for integration tests

Convert the typed fixtures from your Vitest or Jest setup into XML seed data for legacy systems and mock servers that still consume XML.

Common questions

Does it use the types or just the object values?

Both. The types decide element names, ordering, and which fields must be present (optional fields become empty elements if missing). The actual value literal supplies the data. If you paste only a const with no interface, the tool uses the literal directly: still works, just without the type-driven safety.

How does it handle optional fields and union types?

Optional fields (field?: T) that are missing from the value are written as empty elements (<field/>) to keep the output shape consistent. Union types (string | number) emit whatever the literal actually contains. Discriminated unions work too: the discriminant becomes an attribute or child element depending on its name.

What about Date, bigint, and enum?

Date values come out as ISO-8601 strings. bigint is emitted as its decimal string (no n suffix). String enums emit the string value, numeric enums emit the number. null becomes an empty element, undefined drops the element entirely unless the field is declared required.

Does it handle generics, Record, and Map?

Mostly. A generic such as ApiResponse<Order> is read through the value you assign, so the concrete Order fields are what appear. Record<string, V> and Map both turn into a sequence of <Entry> elements, each holding a <Key> and a <Value>. Tuples are written as <Item1>, <Item2> and so on, and as const arrays emit their literal values.

Can I paste a whole types.ts file?

Yes. Paste as much TypeScript as you like. Import statements are ignored, type-only declarations define the shape, and the first exported or top-level typed const is what gets serialized. If there are multiple candidates, the one with the most resolvable fields is picked.

Is my code stored?

Convert uploads the TypeScript for that single request and the converted output travels back with the reply; the site keeps no copy. A config.ts or environment.ts pasted along with the types can hold API keys, so leave those files out or blank the values.

Other tools you may need

For the reverse direction, a JSON version of the same object, or a closer look at the XML itself, these are useful next: