Paste Lua on the left and click "Convert": we will turn it into XMLPaste Lua code

What this tool does

Getting XML out of a Lua table usually means writing a recursive function full of .. concatenation and remembering to escape &. xml2lua is good at reading XML into tables, but the other direction is left to you. Paste a table literal here, whether it is a game save, an OpenResty config block or a payload for a Redis script, and you get XML back with each key, subtable and list entry in place.

Lua tables do double duty as records and arrays, and the converter treats each part accordingly. String keys like { customerName = "Ava Chen" } become named child elements. The sequence part, the { "a", "b", "c" } style, becomes a parent with one child per entry, which is how the sample's items list comes out. A table that has both keeps the named keys as children and puts the numbered entries in their own nested group. true, false and numbers keep their literal text, and a key you set to nil still shows up as an empty element.

A few Lua idioms are handled the way a person would hope. local declarations are stripped so local order = { ... } just uses the table inside. A trailing return order at the end of a module file is recognised and the returned table becomes the document root. Long strings written with [[ ... ]] come through as text content with whitespace preserved. Keys that are not valid XML element names (["content-type"], [1], ["2024-04"]) are rewritten to a safe tag name so the document still parses. If you are new to the quirks of how Lua treats integer vs string keys, the Programming in Lua book has a useful chapter on it.

How to use it

Paste a table, press Convert, copy the XML. A one-line literal and a module file that ends in return order follow the same path.

1

Paste your Lua (or try the sample)

Paste Lua into the left editor: a bare table constructor, a local order = {...} assignment, or a whole module that ends in return. Load Sample fills in an order table with a nested items list and a shippingAddress subtable, finished with return order.

Comments, require() lines and helper functions can stay in the paste; only the table data ends up in the XML. Metatables are not evaluated, so values computed by __index will not appear.

2

Hit Convert

Press the green Convert button. The Lua is sent to the backend, which separates each table's array part from its hash part, works down through the subtables and returns the document. A "Converting..." overlay covers the editors until then.

3

Copy the XML

The XML appears in the read-only right panel, two-space indented with a declaration at the top, and it parses cleanly in LuaExpat or any other XML parser. Copy it into a config file, a test fixture or your docs.

When this actually comes in handy

Game config files

Your Love2D or Defold project keeps level data as a Lua table, but your level editor or publishing pipeline wants XML. Paste the Lua, copy the XML, no ad-hoc converter script to maintain.

Nginx / OpenResty config payloads

If you build request or response bodies as Lua tables inside an ngx.location.capture call and need XML output, this saves writing a concatenation helper. Nested tables become nested elements cleanly.

Redis Lua script payloads

Redis scripts that return structured tables (for logging, audit trails, or downstream ingestion) sometimes need to be shipped as XML to legacy consumers. Paste the table literal, get XML that drops straight into the pipeline.

Converting between xml2lua and other tooling

Teams that use xml2lua for the XML-to-Lua direction sometimes need the reverse for tests and fixtures. This gives you a quick, visual check of what a Lua table should look like as XML before committing to a hand-written serializer.

Common questions

How are array-style and hash-style tables handled differently?

An array-style table ({ "a", "b", "c" }) becomes a container element with numbered children named after the parent (or a generic <item> tag). A hash-style table ({ name = "Ava" }) becomes an element with named children. A mixed table, both a sequence part and string keys, gets both shapes side by side so nothing is lost.

What about string keys vs integer keys?

String keys become element names directly: { orderId = "ORD-4821" } → <orderId>ORD-4821</orderId>. Integer keys used as a sequence (1, 2, 3, ...) become positional children. Integer keys with gaps, or non-integer numeric keys, are emitted with an index attribute so the mapping is preserved. See the Lua 5.4 reference manual for the underlying semantics.

Does it handle nested tables and mixed types?

Yes. Arbitrary nesting, mixed string / integer keys, tables-in-arrays, arrays-in-tables. Nested subtables come through as nested elements with their own children. Booleans print as true/false, numbers stay as their literal text, and nil becomes an empty self-closing element so the shape stays stable across records.

What happens to keys with dashes or reserved characters?

Keys like ["content-type"] or ["2024-04"] are legal in Lua but illegal as raw XML element names. The converter rewrites them to a safe tag (for example content_type) and preserves the original name as an attribute. If strict round-tripping matters, look the output over before using.

Can I paste a whole module file?

Yes. local declarations, require() lines, helper functions, and comments are ignored. If the file ends in return t, the returned table becomes the document root. If there is just a single top-level table literal, that is used instead.

Is my code stored?

Lua tables go to the backend so the XML can be produced there. Once the response arrives nothing from the request is kept, and the editor content is gone when you close the tab. Game and OpenResty configs sometimes hold shared secrets or upstream passwords, so blank those values out first; the structure is all the converter needs.

Other tools you may need

With a Lua table turned into XML, these pages help you validate or reformat it, read it back as a tree, or produce JSON instead: