JavaScript to XML Converter
Paste a JavaScript object, class, or instance. Get clean XML back.
Input
Output
Paste your JavaScript code on the left and press Convert.
Or drop a file on this box, , or .
What this tool does
Turning a JavaScript object into XML has no one-liner. XMLSerializer only works on DOM nodes, DOMParser goes from XML to DOM, and building the tree with createElement calls is easy to get slightly wrong. When you need the XML for a SOAP call, a feed or a sitemap, paste the JS here and read off the XML. A plain object, an ES6 class with a new call, or something nested several levels deep all work.
Values are mapped with JavaScript's quirks in mind. Numbers and booleans are written as text, a Date comes out the way toISOString() prints it, and a BigInt such as 9007199254740993n keeps every digit but loses the n. null and undefined both leave an empty tag behind. An array property gets a wrapper with one child per element: class instances are named after their class, so the sample's items holds <OrderItem> children, while plain objects and primitives get the singular of the key or Item.
Class definitions are handled too. A class Order { constructor(...) { this.x = ...; } } plus const order = new Order(...) gives you an <Order> root with every property that got assigned in the constructor. Nested class instances expand as nested elements. Methods, getters, symbol-keyed properties, and properties starting with # (private fields) are skipped. If you paste just a plain object literal, that object is serialized directly with a sensible root element name.
How to use it
Paste the code, press Convert, copy the XML. A three-line literal and a module with several classes go through the same way.
Paste your JavaScript (or try the sample)
Paste JS into the left editor: a plain object literal, an ES6 class with a new instance, the return value of a factory function, or a Node.js module.exports. Load Sample sets up three classes and a new Order(...) call with positional constructor arguments.
Leave const, let, and import statements in. You do not need to strip them: the parser knows to ignore wrapping syntax and read the actual values.
Hit Convert
Press the green Convert button. The script is not run in your browser; it is sent to the backend, which works out which constructor argument ends up in which this.x field and returns the XML. A "Converting..." overlay sits over the editors in the meantime.
Copy the XML
Two-space indented XML with a declaration line fills the read-only pane on the right, ready for any XML parser. Copy it into a SOAP body, an RSS or Atom template, or a fixture file for your tests.
When this actually comes in handy
Building SOAP request bodies
You have a plain JS object that mirrors a SOAP request and need the XML body to drop into SoapUI, Postman, or a fetch call. Paste the object, copy the XML, move on.
Generating RSS and Atom feeds
Turn a feed object with title, link, and items into a well-formed XML skeleton you can wrap in the proper RSS envelope, no handwritten element building.
Starting sitemap.xml files
Paste an array of URL objects and get the scaffolding you need for a <urlset> sitemap. Swap in the proper namespace and you are done.
Seeding integration tests
Convert the fixture objects from your Jest or Vitest setup into XML seed data for legacy systems, mock servers, or any consumer that still speaks XML.
Common questions
Does it work with plain objects, ES6 classes, and arrays?
Yes. An object literal uses its keys as element names. With an ES6 class and a new call, the class name becomes the root element and the this.x = ... assignments in the constructor decide the children. An array property gets one child per entry, named after the class of its items when they are instances, otherwise after the singular of the key.
How does it handle Date, BigInt, and null?
A Date becomes its ISO-8601 string. A BigInt is written as plain digits without the n, so values past Number.MAX_SAFE_INTEGER survive. Properties set to null or undefined still get a self-closing tag, which keeps an XSD that requires the element happy even when there is no value.
What about methods, getters, and private fields?
Methods and getters on a class are skipped, only data properties that actually got assigned on the instance are serialized. Private fields declared with #, symbol-keyed properties, and properties on the prototype (not the instance) are also skipped. This matches what JSON.stringify would do.
Can I paste just an object literal without a class?
Yes. A raw const data = { ... } works fine: the outer variable name is used as the root element, or a generic <root> if there is no binding. Nested objects and arrays inside expand as nested elements the same way.
Does it escape special characters like &, <, and >?
Yes. Text content containing &, <, >, ", or ' is escaped to the corresponding XML entities so the output always parses back cleanly. Unicode characters are kept as-is and the output is UTF-8.
Is my code stored?
Even though it is JavaScript, your code is never executed: the text goes to the backend, comes back as XML, and is not saved. Front-end code is the usual place for hard-coded API keys, so swap those for dummy strings before you paste.
Other tools you may need
After converting a JS object to XML, these pages help you check the document, reformat it, or get the JSON version instead: