XML Converter
Convert XML into JSON, YAML, TOML, JavaScript object literals, or PHP arrays. The browser XML parser reads your document, then a structured mapping turns elements into keys, repeated siblings into arrays, and attributes into prefixed fields so the output keeps the original shape. It handles everyday XML sources — SOAP responses, RSS and Atom feeds, sitemaps, SVG, Android and Maven configuration, and legacy API messages — and lets you choose how attributes, text values, and numbers are treated. A checks panel summarises the root element, element and attribute counts, namespace prefixes, mixed content, and CDATA. Parse errors come with line, column, and surrounding context. Parsing, conversion, and copying all happen in this browser tab; nothing is uploaded, proxied, or logged on a server.
- One XML input feeds five targets — JSON, YAML, TOML, JavaScript object literals, and PHP arrays — each with its own options
- Attributes map to prefixed keys (configurable, default @) or can be dropped entirely when you only need element content
- Repeated child elements collapse into arrays and text values can be coerced to numbers and booleans, or kept verbatim
- A checks panel reports the root element, element and attribute counts, nesting depth, namespace prefixes, mixed content, and CDATA
- Fully local processing — no upload, no telemetry — safe for production messages, SOAP captures, and config samples
Overview
A focused tool for work that starts from XML. Element-to-key mapping, array collapsing for repeated siblings, attribute handling, and value coercion are resolved at parse time so the output is ready for downstream APIs, configuration loaders, JSON Schema validators, or code generators without a second manual cleanup pass.
- 01
Five target formats out of the box
XML to JSON, YAML, TOML, JavaScript object literal, and PHP array. JSON exposes indent size and alphabetical key sort; YAML and TOML emit a clean nested structure; TOML enforces an object root rather than half-output; JS object literals keep quoted keys and proper escaping; PHP arrays emit a full <?php return [...]; file.
- 02
Predictable element-to-object mapping
Each element becomes an object keyed by its tag name, text content becomes the value, and repeated sibling elements collapse into an array in document order. The root element name is preserved as the top-level key so the output mirrors the source tree.
- 03
Attributes you control
Attributes map to keys with a configurable prefix (default @) so they never collide with child element names. Turn attributes off entirely when you only care about element content, and when an element carries both attributes and text the text moves to a #text field.
- 04
Optional value typing
Numeric and boolean text can be coerced to real numbers and booleans, or kept as strings. Coercion only applies when a value round-trips exactly, so leading-zero codes, version-like strings, phone numbers, and integers beyond the safe range stay as text.
- 05
A checks panel for unfamiliar XML
The panel summarises the root element, element and attribute counts, nesting depth, namespace prefixes, mixed content, and CDATA usage so a strange document becomes legible before you trust the conversion.
- 06
Runs entirely in the browser
Parsing, conversion, checks, and copy all happen on this page using the browser XML parser. Your XML never leaves through a request to a server, CDN, or third-party analytics platform — safe for production messages and config samples.
How to use
The workflow collapses into four steps: paste XML, pick a format, scan the checks panel, and copy the result.
- 01
Paste XML into the input panel on the left. Parsing happens immediately and the checks panel surfaces the root element, counts, namespace prefixes, and mixed-content warnings.
- 02
Pick a target at the bottom: JSON, YAML, TOML, JavaScript object, or PHP array. JSON adds indent size and key sort; the output updates live as you switch.
- 03
Tune the parse options: keep or drop attributes, change the attribute prefix, and decide whether numeric and boolean text is coerced or kept verbatim.
- 04
Read the checks panel. Mixed content and CDATA are flagged but never block conversion; they mark places where text and structure overlap so you can confirm the shape is what you expect.
- 05
Click copy and paste the output into your IDE, snippet manager, API client, or config loader to continue the workflow.
Details
The recurring rough edges of everyday XML work are smoothed out by default — no need to chain external tools just to get a clean conversion.
- Parsing uses the same XML engine your browser ships, so well-formedness rules match what other standards-based parsers expect.
- Repeated sibling elements always become arrays in document order, so list-like XML maps to predictable JSON, YAML, and TOML.
- Attribute prefixing keeps attributes and child elements distinct, and a single toggle drops attributes when you only need element content.
- JSON output preserves element order, with an opt-in alphabetical sort for stable git diffs, code review, and JSON Schema validation.
- TOML conversion requires an object root and reports clearly rather than emitting a half-finished file that no parser will accept.
- JavaScript object and PHP array outputs preserve nesting, escaping, and literals so the result drops directly into test data, config, or examples.
- The checks panel lists root element, counts, depth, and namespace prefixes so an unfamiliar XML file becomes legible in seconds.
- Everything runs in the browser — no SaaS backend — so the tool keeps working on a flight, in a VPN-only network, or behind an enterprise proxy.
Use cases
Whenever the source is XML, the following everyday tasks shed a layer of manual copy-paste or screenshot-and-describe.
-
Turn SOAP responses into JSON
Paste a SOAP or legacy XML API response and read it as JSON so you can map fields into a modern client, test data, or a TypeScript type without parsing angle brackets by hand.
-
Read RSS and Atom feeds as data
Convert a feed to JSON or YAML to inspect item titles, links, and dates, then feed the structured result into a script, a static-site generator, or a content pipeline.
-
Migrate XML config to YAML or TOML
Moving away from web.xml, a Spring XML context, or a Maven pom.xml? See the YAML or TOML output first, then refine by hand instead of retyping the whole tree.
-
Inspect SVG structure
Convert an SVG to JSON to walk its groups, paths, and attributes programmatically, or to extract specific attribute values without a full XML DOM library.
-
Build test data from sample messages
Backends and partners often share XML samples. Convert them to JSON or JS objects so frontend Jest, Vitest, and Storybook tests can use the same data shape.
-
Generate PHP config from XML
Turn a legacy XML settings file into a <?php return [...]; array that drops straight into a Laravel or WordPress project, keeping nesting and escaping intact.
-
Compare two XML documents
Convert both files to JSON, then run a structured diff to see exactly which elements, attributes, and values changed between two revisions of a message or config.
-
Teach and document XML structure
Convert nested XML to JSON or YAML so example documents read clearly in articles, course notes, and onboarding material without deep angle-bracket indentation.
See also
When the source on your desk is YAML instead — a Kubernetes manifest, a Helm values file, a CI workflow — and you need to walk toward JSON, TOML, XML, JavaScript object literals, or PHP arrays, reach for YAML Converter . If the XML itself needs a cleanup first — pretty-printing a minified message, folding deep nodes, or confirming it is well-formed before you trust the conversion — pass it through XML Formatter , which indents, minifies, and validates XML with line and column error reporting. And when you already have JSON and want to move it into YAML, XML, CSV, TOML, JavaScript objects, or PHP arrays, use JSON Converter to convert in that direction with format-specific options, keeping a single source of truth instead of hand-editing each target.
Best practices
XML carries information in three places at once — elements, attributes, and text — so a clean conversion depends on deciding how each one should map. A few small habits keep results predictable across every project.
- Decide up front whether attributes matter. Keep them with a clear prefix when they carry data, or drop them when you only need element content.
- Turn off value coercion when your XML holds identifiers, version strings, leading-zero codes, or phone numbers that must stay as text.
- Watch for mixed content — text sitting next to child elements. It merges into a #text field, which is rarely what you want; restructure the source if the text is meaningful.
- Remember that a single occurrence of an element is an object while two or more become an array. If a list can have one item, handle both shapes downstream.
- After converting XML to JSON, run the result through a JSON diff against the previous version to catch silent field changes before they reach production.
- XML comments and processing instructions are dropped during conversion. Promote anything essential into real elements or external documentation.
- Namespaces stay as literal prefixes on keys (for example soap:Body). Decide whether downstream code expects the prefix or a stripped local name.
- For very large documents, validate your options against a representative slice first, then convert the full file once the shape looks right.
Limitations
Knowing what the tool does not do keeps you from reaching for it as a full XML IDE, schema validator, or transformation engine.
- No schema validation: DTD, XML Schema (XSD), and RELAX NG rules are out of scope — a well-formed document is not the same as a valid one.
- No XSLT or XPath: the tool maps structure to other formats but does not transform with stylesheets or evaluate path expressions.
- XML comments, processing instructions, and the declaration are not preserved in the output; only elements, attributes, and text are mapped.
- Mixed content (text interleaved with child elements) cannot always map cleanly; the text is collected into a #text field and ordering between text and elements is not preserved.
- It does not resolve external entities, DOCTYPE includes, or namespace URLs; everything is treated as local text and nothing is fetched, which also avoids entity-expansion risks.
- Round-tripping is not guaranteed: converting XML to JSON and back will not always reproduce the original document byte for byte, since several XML constructs have no direct JSON equivalent.
- Very large files (multiple megabytes) may slow the browser, but processing stays local — nothing is truncated or uploaded.
FAQ
Common questions cover attribute handling, arrays, value typing, namespaces, and whether data leaves the browser.
How are attributes represented?
By default each attribute becomes a key prefixed with @ (configurable) so it never clashes with a child element name. You can change the prefix or turn attributes off entirely when you only need element content. When an element has both attributes and text, the text is stored under a #text key.
Why did repeated elements become an array?
When an element appears more than once under the same parent, the values collapse into an array in document order — that is the only lossless way to represent siblings in JSON, YAML, or TOML. Note that a single occurrence stays an object, so a list that can hold one item may appear as either shape; handle both downstream.
Why is my number still a string?
Value coercion only converts text that round-trips exactly, so "007", "1.0", phone numbers, and integers beyond the JavaScript safe range stay as strings to avoid losing data. Turn off "Parse numbers & booleans" to keep every value as text, which is safest for identifiers and codes.
What happens to namespaces?
Namespace prefixes are kept literally on the keys, so soap:Body becomes the key "soap:Body". The tool does not strip or resolve namespace URLs. The checks panel lists the prefixes it found so you can decide whether downstream code expects them.
Why does TOML conversion say the root must be an object?
TOML requires a table at the top level. The converter always wraps output under the root element name, so this usually only appears for unusual inputs; if it does, the JSON output shows the shape and you can adjust before converting to TOML.
Are comments and CDATA kept?
Comments, processing instructions, and the XML declaration are dropped — only elements, attributes, and text are mapped. CDATA sections are read as ordinary text, and the checks panel notes when CDATA is present so nothing surprises you.
Can I convert the result back to XML?
This tool converts from XML. To go the other way, the JSON Converter and YAML Converter can emit XML. Round-tripping is not guaranteed to be byte-identical because several XML constructs have no direct JSON equivalent.
Does pasted data get uploaded?
No. Parsing, conversion, checks, and copy all happen in the browser using its built-in XML parser. No request carries your XML out of this page to a server, CDN, or analytics platform, so it is safe for production messages and secret sample data.
Related tools
Keep moving through data work: convert in the other direction, pretty-print or validate XML, or reshape JSON for the next step. The tools below chain into a full workflow.