Overview
Introduction
Nested XML is great for representing hierarchy, but plenty of tools downstream, spreadsheets, log pipelines, flat config formats, don't understand nesting at all. This tool collapses a document down to one level.
It's the fastest path from an arbitrarily nested XML document to a flat list of key/value pairs.
What Is XML Flattener?
A flattening tool that converts XML to its equivalent JSON, then collapses every nested object and array into a single-level object using dot notation for object keys and bracket notation for array indices.
It reuses the existing XML to JSON Converter and JSON Object Flattener, so its output matches what you'd get chaining those two tools manually.
How XML Flattener Works
XML is first converted to a JSON value the same way the XML to JSON Converter does it, attributes as @-prefixed keys, repeated siblings as arrays.
That JSON is then walked recursively; every leaf value's full path (joined by dots for object keys, [index] for array items) becomes a flat key in the output.
When To Use XML Flattener
Use it when you need XML data as flat key/value pairs for a spreadsheet, log line, or flat config format.
It's also a fast way to see every distinct data path in a deeply nested document at once.
Often used alongside XML to JSON Converter and XML to Table Converter.
Features
Advantages
- Handles arbitrarily deep nesting and repeated elements automatically.
- Runs entirely client-side.
- Uses the same flattening convention as the JSON Object Flattener, so behavior is predictable if you already know that tool.
Limitations
- Output is JSON text, not CSV or a table, use XML to CSV Converter or XML to a Table if you want a tabular view instead.
- Very wide or deep documents can produce very long, hard-to-scan key names.
Examples
Best Practices & Notes
Best Practices
- Use this before exporting XML data to a flat config format or a single-row log line.
- Pair with XML to a Table when your data is naturally row-shaped instead, a table is usually more readable than a long flat key list.
- Skim the key list once first, it doubles as a quick map of every distinct data path in the document.
Developer Notes
This is a thin composition: `xmlToJson` followed by the JSON category's existing `flattenJsonObject`, no flattening logic is duplicated here.
XML Flattener Use Cases
- Preparing XML data for a flat-key config format or environment variables
- Producing a single log line from a nested XML record
- Seeing every distinct data path in a deeply nested document at once
Common Mistakes
- Expecting a table or CSV output, this tool produces flat JSON; use XML to a Table or XML to CSV Converter for tabular output.
- Trying to hand-parse the flattened keys back into nested structure, there's no built-in "unflatten" step here.
Tips
- If key names get unwieldy, consider XML to a Table instead for naturally row-shaped data.
- Check the FAQ above if the output doesn't look like what you expected.