XML to JSON: Convert Legacy XML Feeds and Configs to JSON
XML was the universal data format before JSON took over. RSS feeds, SOAP APIs, configuration files, and many legacy systems still use XML. This converter parses XML and produces idiomatic JSON — attributes prefixed with @, repeated sibling elements merged into arrays, text-only elements simplified to string values.
Attributes → @attr keys. Two or more same-name siblings → array. Single element → object (not array). Text-only element → string value.
XML-to-JSON Conventions
There is no single standard for XML-to-JSON mapping. The most common convention (used by xml2js, xml-js, and this tool) is: attributes get a @ prefix; text content gets a #text key when mixed with other properties; repeated sibling elements become arrays; single elements stay as objects. Some tools always produce arrays (even for single elements) — if your consumer expects that behavior, you'll need to adjust the output.
Use Cases
Converting RSS/Atom feeds for processing in JavaScript. Parsing SOAP API responses to extract data. Reading Android resource XML files. Consuming configuration XML from legacy systems. Transforming Maven pom.xml for dependency analysis. The output is valid JSON that can be queried with JSONPath or processed with jq.
After Conversion: Querying with JSONPath
Once you have JSON, use the JSONPath Finder tool to query specific values. $..title extracts all title values recursively. $.library.book[*].@id extracts all book IDs. $.library.book[?(@.@genre == 'fiction')] filters by attribute value. This is far more expressive than XPath and works with standard JSON tools.
Conversion Rules
- Attributes → @attribute keys
- Repeated siblings with same tag → JSON array
- Single element → JSON object
- Text-only elements → string value
- Mixed content (text + children) → #text key
Frequently Asked Questions
How are XML attributes converted?
XML element attributes are converted to JSON keys with an @ prefix. For example,
How are repeated elements handled?
When multiple sibling elements have the same tag name, they are collected into a JSON array. For example, three
What happens to element text content?
If an element has only text content (no attributes or child elements), the text becomes the value directly. For example,
What XML features are not supported?
Namespaces (xmlns, ns:element) are preserved as-is in tag names. XML entities (& < > " ') are left un-decoded by this parser — pass clean XML with no custom entities. CDATA sections are converted to their text content. Processing instructions () are stripped. DTD declarations are stripped.