XML ↔ JSON Converter avatar

XML ↔ JSON Converter

Pricing

Pay per event

Go to Apify Store
XML ↔ JSON Converter

XML ↔ JSON Converter

🔄 Convert between XML and JSON in both directions. Handles RSS feeds, SOAP responses, config files, and any structured data. Supports attributes, CDATA, arrays, URL input, and bulk processing.

Pricing

Pay per event

Rating

0.0

(0)

Developer

Stas Persiianenko

Stas Persiianenko

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

3 days ago

Last modified

Share

Instantly convert XML to JSON or JSON to XML — bidirectional, fast, and free to try. Handles RSS feeds, SOAP responses, config files, API payloads, and any structured data format. No proxy, no scraping — pure computation.


What Does It Do?

The XML ↔ JSON Converter transforms data between XML and JSON formats in both directions:

  • 📄 XML → JSON: Parse any XML document (RSS feeds, SOAP responses, sitemaps, config files) into clean JSON
  • 🔁 JSON → XML: Serialize JSON objects or arrays back into well-formed XML
  • 🤖 Auto-detect mode: Paste data without specifying the format — the actor detects whether it's XML or JSON automatically
  • 🔗 URL input: Provide a URL to an XML or JSON file — the actor fetches and converts it
  • 📦 Bulk mode: Process multiple conversion tasks in a single run using the inputs array

Data passes through the fast-xml-parser library — a battle-tested, high-performance parser used by millions of npm projects.


Who Is It For?

Backend Developers

You're integrating with a legacy SOAP API that returns XML, but your app speaks JSON. This actor handles the translation as a step in your pipeline — no custom parsing code required.

Data Engineers & ETL Pipeline Builders

You receive RSS/Atom feeds, Sitemap XML files, or third-party XML exports and need them as JSON for downstream processing in tools like n8n, Make, or Zapier. Feed the URLs in, get JSON out.

No-Code / Low-Code Automators

You're building workflows in n8n or Make and hit a wall because an API returns XML. Drop this actor in as a conversion step and carry on with JSON-native logic.

QA Engineers & API Testers

You're testing SOAP/REST hybrid APIs and need to quickly inspect or transform XML payloads during debugging sessions.

System Administrators

You manage configuration files in XML (pom.xml, web.config, Ant build files) and want them as JSON for tooling, validation, or migration.


Why Use This Actor?

  • Instant results — pure computation, no browser, no proxy, no scraping delays
  • 🏷️ Attribute preservation — XML element attributes are captured under @attributes keys, not lost
  • 🌊 CDATA support — CDATA sections are handled natively via the __cdata property
  • 📐 Correct array detection — repeated sibling XML elements automatically become JSON arrays
  • 🎛️ Flexible output — pretty-printed or compact, custom root element names, custom array item node names
  • 💸 Ultra-low cost — $0.01 start + $0.0015 per conversion (see Pricing below)
  • 🔗 URL input supported — fetch and convert remote XML/JSON files by URL directly

Extracted Data

Each conversion task produces one output item in the dataset:

FieldTypeDescription
inputIndexNumberTask sequence number (1-based)
modeStringActual conversion mode used: xmlToJson or jsonToXml
outputFormatStringOutput format: json or xml
inputPreviewStringFirst 150 characters of input data
outputStringThe converted output (JSON string or XML string)
errorStringError message if the conversion failed (field absent on success)

How Much Does It Cost to Convert XML to JSON?

Pricing uses Pay-Per-Event — you only pay for what you use. There are no monthly subscriptions.

EventFREE PlanBRONZESILVERGOLDPLATINUMDIAMOND
Run start (one-time)$0.010$0.0095$0.0085$0.0075$0.0060$0.0050
Per conversion$0.0015$0.00135$0.0012$0.00098$0.00075$0.0006

Example costs:

  • Convert 1 XML file: ~$0.0115 (start + 1 conversion)
  • Convert 10 XML files in bulk: ~$0.025 (start + 10 conversions)
  • Convert 100 files in bulk: ~$0.160 (start + 100 conversions)

All Apify accounts include a free monthly compute budget to try actors at no charge. The FREE plan pricing applies within that budget.


How to Use the XML ↔ JSON Converter

Step 1: Choose Your Input Method

You can provide input data in two ways:

  1. Paste data directly — put your XML or JSON string in inputData
  2. Provide a URL — put the URL of an XML or JSON file in inputUrl

Step 2: Select the Conversion Mode

  • Auto-detect (recommended): the actor inspects your input and picks the right direction automatically
  • XML → JSON: explicitly convert XML to JSON
  • JSON → XML: explicitly convert JSON to XML

Step 3: Configure Options

  • Parse XML Attributes: include element attributes in JSON output (under @attributes key)
  • Root Element Name: when generating XML from JSON, wrap output in this root element (default: root)
  • Pretty Print: format output with indentation (recommended for readability)
  • Array Item Node Name: when a JSON array is at the root, wrap each item in this XML element name (default: item)

Step 4: Run and Collect Results

Click Start and the results appear in the Dataset tab. Each conversion task produces one row. Download as JSON, CSV, or use the API.


Input Parameters

ParameterTypeDefaultDescription
inputsArrayArray of conversion tasks (bulk mode). Each item can override all other settings.
modeStringautoConversion direction: auto, xmlToJson, or jsonToXml
parseAttributesBooleantrueInclude XML attributes in JSON output under @attributes key
rootElementStringrootRoot XML element name when converting JSON → XML
prettyPrintBooleantrueFormat output with indentation and line breaks
arrayNodeNameStringitemXML element name for array items when root is a JSON array

Bulk Mode Input Item

Each item in the inputs array supports:

FieldTypeDescription
inputDataStringRaw XML or JSON string to convert
inputUrlStringURL of an XML or JSON file to fetch and convert
modeStringOverride conversion mode for this task
parseAttributesBooleanOverride attribute parsing for this task
rootElementStringOverride root element for this task
prettyPrintBooleanOverride pretty-print for this task
arrayNodeNameStringOverride array item node name for this task

Output Examples

XML → JSON (with attributes)

Input XML:

<catalog>
<book id="1">
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<price>9.99</price>
</book>
<book id="2">
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<price>12.99</price>
</book>
</catalog>

Output JSON:

{
"catalog": {
"book": [
{
"@attributes": { "id": 1 },
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"price": 9.99
},
{
"@attributes": { "id": 2 },
"title": "To Kill a Mockingbird",
"author": "Harper Lee",
"price": 12.99
}
]
}
}

JSON → XML

Input JSON:

{
"employees": [
{"name": "Alice", "role": "Engineer"},
{"name": "Bob", "role": "Manager"}
]
}

Output XML (root element: company):

<?xml version="1.0" encoding="UTF-8"?>
<company>
<employees>
<name>Alice</name>
<role>Engineer</role>
</employees>
<employees>
<name>Bob</name>
<role>Manager</role>
</employees>
</company>

Tips and Best Practices

💡 Use auto-detect for quick conversions — the actor correctly identifies XML (starts with <) vs JSON (starts with { or [) in virtually all cases.

💡 Process RSS/Atom feeds via URL — put the feed URL in inputUrl and set mode to auto. The actor fetches and converts in one step.

💡 Bulk-convert multiple files in one run — use the inputs array to process many files in a single run. This saves the start cost compared to launching separate runs for each file.

💡 XML attributes are under @attributes — when parseAttributes is true (default), element attributes are captured cleanly under a dedicated key, not mixed with child elements.

💡 Repeated XML elements become JSON arrays automaticallyfast-xml-parser detects repeated sibling elements and converts them to arrays. You don't need to configure this.

💡 Use compact output for storage — set prettyPrint: false for compact output when you're piping the result into another system (saves bandwidth and storage).

💡 Set a meaningful rootElement for JSON → XML — instead of the generic root, use a domain-specific name like products, orders, or employees to produce readable XML.


Integrations

n8n: Convert XML API Response to JSON

  1. Use an HTTP Request node to call your XML API
  2. Add an Apify node, select XML ↔ JSON Converter
  3. Pass the response body as inputData with mode: xmlToJson
  4. Use the JSON output in downstream nodes

Make (formerly Integromat): Transform Webhook Payloads

  1. Receive an XML webhook payload in a Webhooks module
  2. Call the XML ↔ JSON Converter via Apify's HTTP module
  3. Parse the JSON output with Make's built-in JSON parser
  4. Route to Google Sheets, Slack, or any other module

Zapier: RSS Feed to Structured Data

  1. Trigger on a schedule with Zapier Schedule
  2. Use Webhooks by Zapier to call the Apify API with the RSS feed URL
  3. Parse the resulting JSON in downstream Zaps

Programmatic Pipeline (Node.js)

const { ApifyClient } = require('apify-client');
const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });
const run = await client.actor('automation-lab/xml-json-converter').call({
inputs: [
{ inputUrl: 'https://example.com/feed.xml', mode: 'auto' },
{ inputData: '{"key": "value"}', mode: 'jsonToXml', rootElement: 'data' }
]
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items.map(item => item.output));

API Usage

Node.js

const { ApifyClient } = require('apify-client');
const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });
const run = await client.actor('automation-lab/xml-json-converter').call({
inputs: [
{
inputData: '<note><to>Tove</to><from>Jani</from><body>Hello!</body></note>',
mode: 'xmlToJson',
parseAttributes: true,
prettyPrint: true
}
]
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items[0].output);

Python

from apify_client import ApifyClient
client = ApifyClient('YOUR_API_TOKEN')
run = client.actor('automation-lab/xml-json-converter').call(run_input={
'inputs': [
{
'inputData': '<note><to>Tove</to><from>Jani</from><body>Hello!</body></note>',
'mode': 'xmlToJson',
'parseAttributes': True,
'prettyPrint': True,
}
]
})
items = client.dataset(run['defaultDatasetId']).list_items().items
print(items[0]['output'])

cURL

curl -X POST \
"https://api.apify.com/v2/acts/automation-lab~xml-json-converter/runs?token=YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"inputs": [
{
"inputData": "<note><to>Tove</to><from>Jani</from><body>Hello!</body></note>",
"mode": "xmlToJson"
}
]
}'

Use With Claude AI (MCP)

You can use this actor directly inside Claude Code, Claude Desktop, Cursor, or VS Code via the Apify MCP server.

Claude Code

$claude mcp add --transport http apify "https://mcp.apify.com?tools=automation-lab/xml-json-converter"

Claude Desktop / Cursor / VS Code

Add to your MCP config (claude_desktop_config.json or .cursor/mcp.json):

{
"mcpServers": {
"apify": {
"type": "http",
"url": "https://mcp.apify.com?tools=automation-lab/xml-json-converter",
"headers": {
"Authorization": "Bearer YOUR_APIFY_API_TOKEN"
}
}
}
}

Example Prompts

Once connected, you can ask Claude:

  • "Convert this XML to JSON: <book><title>Dune</title><author>Frank Herbert</author></book>"
  • "Fetch the RSS feed at https://example.com/feed.xml and convert it to JSON"
  • "Turn this JSON array into an XML file with root element 'products' and item node 'product'"
  • "I have 3 XML files to convert — process them all in one bulk run"

Legality

This actor converts data between formats. It does not scrape, crawl, or access any protected website. All data processing happens on the input you provide. Using this actor does not involve bypassing any access controls or terms of service.


Frequently Asked Questions

What XML features are supported?

The actor supports all standard XML including: element attributes, CDATA sections, nested elements, text nodes, repeated elements (arrays), XML namespaces (treated as attributes), and XML with or without an XML declaration (<?xml version="1.0"?>).

Are XML namespaces supported?

Namespace prefixes (e.g., <ns:element>) are treated as part of the element name. Namespace declarations (xmlns:ns="...") are captured as attributes when parseAttributes is enabled.

What happens if I provide invalid XML or JSON?

The actor catches the error gracefully and records it in the error field of the output item. Other tasks in a bulk run continue processing normally — one bad input doesn't stop the rest.

Can I convert very large XML files?

Yes — the actor runs in the Apify cloud with up to 256 MB RAM. For extremely large files (multi-MB XML), the conversion still completes efficiently because fast-xml-parser is a streaming-capable parser. If you hit memory limits, contact support.

Why are my repeated XML elements not becoming an array?

fast-xml-parser automatically converts repeated sibling elements with the same tag name into an array. If you see a single element not wrapped in an array, it's because there was only one occurrence of that tag in the input. This is correct behavior — a <book> tag that appears once is an object, not a single-element array.

Can I fetch XML from a URL that requires authentication?

Not currently. inputUrl supports public URLs only. For authenticated sources, fetch the XML yourself and pass it via inputData.

What's the difference between rootElement and arrayNodeName?

  • rootElement (default: root) is the outer wrapper element that always wraps the entire JSON output when converting to XML
  • arrayNodeName (default: item) is used when the JSON root is an array — each array element gets wrapped in an element with this name

Looking for other format converters or data transformation tools?