Overview
Introduction
Sometimes the destination for converted XML data isn't a code editor but a URL parameter, a log line, or a network payload, places where every extra whitespace byte adds up. This converter turns XML straight into JSON that's already minified, so there's no separate minify step after the conversion.
It runs entirely in your browser: paste XML in, get compact JSON out, with the same parsing this site's other XML tools use.
What Is XML to Compressed JSON?
An XML-to-compressed-JSON converter walks a parsed XML document tree and maps its elements, attributes, and text content onto an equivalent plain JavaScript value, then serializes that value as JSON with no indentation, no line breaks, and no extra spaces.
It uses a hand-written parser rather than the browser's DOMParser, so conversion behaves identically whether it runs client-side or during any future server-side rendering pass.
How XML to Compressed JSON Works
Your XML is tokenized into tags and text runs, then assembled into a tree using a stack-based parser that tracks open and close tags in the same spirit as a SAX parser.
Each element's attributes become @-prefixed keys, an element whose only content is text takes that text as its value directly, and any tag name that repeats among siblings is collected into a JSON array. The resulting value is then passed straight to JSON.stringify with no space argument, which is what keeps the output compact.
When To Use XML to Compressed JSON
Use it when the converted JSON needs to travel somewhere size-sensitive: a query string, a cookie, a QR code, or a compact log entry.
It's also useful any time you want the smallest possible JSON representation of an XML payload without running the output through a separate minifier afterward.
Often used alongside XML to JSON Converter, JSON Minifier and XML Minifier.
Features
Advantages
- Runs entirely client-side, so XML containing real config or credentials never leaves your browser.
- Skips the extra minify step: output is already compact, no need to pipe it through a separate JSON minifier tool.
- Uses the same attribute/array mapping as the standard XML to JSON converter, so the data shape stays predictable and familiar.
- Smaller output size makes it easier to paste into space-constrained places like URLs or single-line log entries.
Limitations
- XML namespaces are folded into the tag name rather than represented as a separate concept.
- Mixed content (text interleaved with child elements at the same level) is a lossy case for any XML-to-JSON mapping, this converter included.
- The compact output has no indentation option; use the regular XML to JSON converter if you need pretty-printed JSON for reading or debugging.
Examples
Best Practices & Notes
Best Practices
- Check how repeated tags convert for your specific document; arrays only form when a tag name repeats among direct siblings, not globally.
- Validate the resulting JSON's shape before wiring it into code that expects a specific structure, minified output is harder to eyeball than indented output.
- Run the XML Validator first if you're unsure whether the source document is well-formed.
Developer Notes
This tool calls the same `parseXml` mapping (from `yaml/lib/xml-core.ts`) that powers the XML to JSON Converter, so the data shape is identical between the two pages; the only difference is that this one calls `JSON.stringify(value)` with no space argument instead of `JSON.stringify(value, null, indent)`. Keeping this as a distinct slug/page lets it be discovered directly rather than requiring users to convert then separately minify.
XML to Compressed JSON Use Cases
- Embedding a parsed XML payload into a URL query parameter or short-lived token where size matters
- Producing a compact JSON log line from an XML event or request body
- Minimizing the size of a JSON fixture generated from an XML sample for tests
- Feeding converted XML data into a network request where bandwidth or payload limits apply
Common Mistakes
- Expecting XML namespaces to be preserved distinctly; they're currently folded into the tag name.
- Assuming mixed content (text and elements interleaved) converts cleanly; it's a lossy case for any XML-to-JSON mapping.
- Forgetting that a single, non-repeated child element becomes an object, not a one-item array, same as the pretty-printed converter.
Tips
- If you need to read the structure before compressing it, check the regular XML to JSON Converter first, then come back here for the compact version.
- Pair with the JSON to XML Converter to check what a round trip does to your specific document.
- Upload a .xml file directly instead of copy-pasting if the document is large.