SwiftVecto SwiftVecto SwiftVecto

Search Results

No matching tools found

Try searching with a different keyword or browse one of our tool categories.

↑ ↓ Navigate Enter Open Esc Close

XML to JSON

Convert XML files to structured JSON while preserving nested elements, repeated nodes, attributes, text values and the original root element.

Selected Files

Total Size

JSON Formatting

Choose whether the generated JSON should be formatted for readability or written in a compact form.

Formatting does not change the data

Pretty formatting changes whitespace only. The converted XML structure, attributes and values remain the same.

How XML Becomes JSON

XML Input

<customer id="1001">
    <name>Michael</name>
    <active>true</active>
    <phones>
        <phone>0123</phone>
        <phone>0456</phone>
    </phones>
</customer>

JSON Output

{
    "customer": {
        "@attributes": {
            "id": "1001"
        },
        "name": "Michael",
        "active": "true",
        "phones": {
            "phone": [
                "0123",
                "0456"
            ]
        }
    }
}

Before You Begin

  • Upload one well-formed XML file up to 50 MB.
  • The original XML root element is preserved as the top-level JSON property.
  • Nested XML elements become nested JSON objects.
  • Repeated sibling elements become JSON arrays automatically.
  • XML attributes are preserved under an @attributes property.
  • Direct element text may be stored under #text when the same XML element also contains attributes or child elements.
  • XML values are preserved as strings rather than automatically converted into numbers, booleans or dates.
  • DOCTYPE and ENTITY declarations are not supported.
  • Your original XML file remains unchanged.

Nested Elements

XML hierarchy is retained instead of being flattened.

XML

<address>
    <city>London</city>
    <postcode>HP1 2AB</postcode>
</address>

JSON

"address": {
    "city": "London",
    "postcode": "HP1 2AB"
}

Repeated Elements

When sibling XML elements share the same name, SwiftVecto groups them into a JSON array.

XML

<phone>0123</phone>
<phone>0456</phone>
<phone>0789</phone>

JSON

"phone": [
    "0123",
    "0456",
    "0789"
]

XML Attributes

XML attributes are preserved separately from child elements so their meaning is not lost during conversion.

XML

<customer
    id="1001"
    status="active">
    <name>Michael</name>
</customer>

JSON

"customer": {
    "@attributes": {
        "id": "1001",
        "status": "active"
    },
    "name": "Michael"
}

Elements With Attributes and Text

When an element contains both attributes and a direct text value, the text is stored under #text.

XML

<price currency="GBP">
    12.50
</price>

JSON

"price": {
    "@attributes": {
        "currency": "GBP"
    },
    "#text": "12.50"
}

Values Preserved as Strings

SwiftVecto does not guess XML text types. Values such as 001245, true and 01/02/2026 remain strings so identifiers and source text are not unintentionally changed.

XML Hierarchy Is Retained

Unlike XML to CSV or XML to Excel, this converter does not need to flatten nested structures because JSON can naturally represent objects and arrays.

External Entities Disabled

XML parsing uses network access restrictions so the converter does not fetch external resources referenced by uploaded XML files.

DOCTYPE and ENTITY Are Rejected

XML documents containing DOCTYPE or ENTITY declarations are rejected because these features are unnecessary for ordinary XML-to-JSON conversion and can introduce security risks.

XML and JSON Have Different Data Models

XML supports concepts such as attributes, mixed text content and namespaces that do not have one universal JSON equivalent. SwiftVecto uses a consistent general-purpose mapping, but specialised systems may require a different structure.

Ready to Process

Your files are processed securely and automatically deleted after processing.

Continue with These Tools

Finished using XML to JSON? Here are some related tools that people commonly use next to complete their workflow faster.

How to Convert XML to JSON

Upload an XML file and convert its hierarchy into structured JSON. SwiftVecto preserves nested elements, repeated sibling elements, attributes, direct text values and the original XML root element while generating UTF-8 JSON.

Overview

The SwiftVecto XML to JSON converter transforms hierarchical XML into structured JSON without flattening the source document. XML elements become JSON properties, repeated sibling elements become arrays, attributes are stored under @attributes, and direct text content is preserved. The original root element remains in the JSON output, making the converted structure easier to understand and more suitable for round-trip data workflows.

Benefits

Convert XML files into JSON.
Preserve the original XML hierarchy.
Keep the root XML element in the JSON output.
Convert nested elements into nested JSON objects.
Convert repeated sibling elements into JSON arrays.
Preserve XML attributes.
Store attributes under a dedicated @attributes property.
Preserve direct text content.
Represent mixed attribute and text values safely.
Preserve empty XML elements.
Preserve values as strings rather than guessing data types.
Preserve leading-zero identifiers.
Generate UTF-8 JSON.
Support pretty or compact JSON output.
Reject unsafe DOCTYPE and ENTITY declarations.
Disable external network entity resolution.
Leave the original XML file unchanged.

How It Works

Upload one well-formed XML file.

SwiftVecto validates the XML before conversion.

DOCTYPE and ENTITY declarations are rejected.

The root XML element becomes the top-level JSON property.

Nested XML elements become nested JSON properties.

Repeated sibling elements are grouped into JSON arrays.

XML attributes are stored under @attributes.

Direct element text is preserved as the element value where possible.

When an element contains attributes or children as well as text, the text is stored under #text.

The converted structure is encoded as UTF-8 JSON.

Download the generated JSON file.

How to Use This Tool

  1. 1
    Choose or drop one XML file.
  2. 2
    Choose whether the JSON should be pretty formatted.
  3. 3
    Start the XML to JSON conversion.
  4. 4
    Wait while SwiftVecto validates and converts the XML structure.
  5. 5
    Download the generated JSON file.

Helpful Tips

  • Use well-formed XML for reliable conversion.
  • Repeated sibling elements naturally become JSON arrays.
  • XML attributes are kept under @attributes instead of being discarded.
  • Direct text may appear under #text when the same XML element also contains attributes or nested elements.
  • Values are preserved as strings so identifiers such as 001245 remain unchanged.
  • Pretty formatting is useful when people need to inspect the JSON.
  • Compact JSON can reduce file size for machine-to-machine use.
  • DOCTYPE and ENTITY declarations are intentionally rejected for security.
  • Review highly complex mixed-content XML if another system requires a strict JSON structure.

Common Uses

Convert an XML API response into JSON.

Convert customer XML records into structured JSON.

Convert product XML containing attributes into JSON.

Convert repeated XML phone elements into a JSON array.

Convert nested XML address structures into nested JSON objects.

Convert XML feeds into JSON for development workflows.

Worked Examples

The following examples demonstrate how this tool can be used in realistic scenarios.

Nested XML

A customer element containing an address child becomes a customer JSON object containing a nested address object.

Repeated elements

Multiple sibling <phone> elements are grouped into a JSON array rather than overwriting one another.

XML attributes

An element such as <customer id="1001"> stores id inside an @attributes JSON object.

Attribute and text

An element such as <price currency="GBP">12.50</price> becomes an object containing @attributes and #text.

Common Mistakes

Avoid these common mistakes to achieve the most accurate results.

  • Uploading malformed XML.
  • Uploading JSON, CSV or HTML renamed to .xml.
  • Expecting every XML value to be automatically converted to JSON numbers or booleans.
  • Assuming XML attributes will become ordinary sibling properties.
  • Expecting XML mixed content to have one universal JSON representation.
  • Including DOCTYPE or ENTITY declarations.
  • Assuming namespace-heavy XML will always map exactly to the structure expected by another application.

Glossary

Definitions of the most important terms used by this tool.

XML

Extensible Markup Language, a hierarchical text format that represents data using elements and attributes.

JSON

JavaScript Object Notation, a structured text format based on objects, arrays and scalar values.

XML Attribute

Metadata attached to an XML element, such as id="1001".

@attributes

The JSON property used by SwiftVecto to preserve XML element attributes.

#text

The JSON property used when an XML element contains direct text together with attributes or child elements.

Repeated Sibling

Two or more XML elements with the same name under the same parent, converted into a JSON array.

Root Element

The single outermost XML element, retained as the top-level JSON key.

XMLReader

A PHP XML parser used to process XML while restricting unsafe network entity behaviour.

Frequently Asked Questions

Can I convert XML to JSON?

Yes. SwiftVecto converts well-formed XML into structured UTF-8 JSON.

Does the converter preserve nested XML?

Yes. Nested XML elements become nested JSON objects.

What happens to repeated XML elements?

Repeated sibling elements are converted into JSON arrays.

Are XML attributes preserved?

Yes. Attributes are stored inside an @attributes object.

What does #text mean?

The #text property stores direct text content when the XML element also contains attributes or nested child elements.

Is the XML root element preserved?

Yes. The original root element becomes the top-level property in the generated JSON.

What happens to empty XML elements?

Empty scalar elements are represented as empty strings.

Are numbers converted to JSON numbers?

No automatic type guessing is performed. XML text values are preserved as strings.

Are true and false converted to booleans?

No. XML text does not provide reliable type metadata by itself, so values such as true and false remain strings.

Are leading zeros preserved?

Yes. Values such as 001245 remain strings and keep their leading zeros.

Can I pretty-format the JSON?

Yes. Pretty formatting adds indentation and line breaks without changing the underlying converted structure.

Why are DOCTYPE and ENTITY blocked?

They are not required for normal XML-to-JSON conversion and external entity processing can create security risks.

Does it support XML namespaces?

Namespaced XML can be parsed, but the converter primarily uses local element and attribute names in the generated JSON structure.

Does SwiftVecto change my XML file?

No. The source XML is copied into an isolated processing workspace and remains unchanged.

Things to Know

  • One XML file is processed per conversion.
  • The XML source must be well formed.
  • DOCTYPE and ENTITY declarations are rejected.
  • External network entity resolution is disabled.
  • The original XML root element is retained.
  • Nested elements remain nested in JSON.
  • Repeated sibling elements become arrays.
  • Attributes are stored under @attributes.
  • Direct text may be stored under #text when required.
  • Values are preserved as strings.
  • Generated JSON uses UTF-8.
  • Pretty formatting can be enabled or disabled.

Disclaimer

XML and JSON have different data models, so there is no single universal mapping for attributes, mixed content, namespaces and repeated structures.

The generated JSON is a consistent general-purpose representation and may require further transformation when another system expects a specific schema.

Values are preserved as strings unless explicit type metadata is available and specialised conversion is implemented.

DOCTYPE and ENTITY declarations are not processed.

Users should review important converted data before relying on it for financial, legal, operational or other critical integrations.

We use cookies

SwiftVecto uses cookies to improve your experience and support free tools through advertising. Privacy Policy · Cookie Policy