XML to JSON Converter Guide — How It Works, Tips & Benefits
Free XML to JSON Converter online — convert xml to json using domparser with attribute support. Step-by-step guide with tips. 100% free, works on mobile. 202...

Try this tool now — 100% free, no signup required
Open ToolIf you've ever integrated with the GSTN e-invoice API, pulled a PAN verification response from NSDL, or debugged a SAP CPI iFlow at an Infosys or TCS client project, you already know the pain: half the Indian enterprise world still speaks XML, but every modern frontend, Node.js service, and MongoDB document wants JSON. Converting between the two by hand — especially when the XML has attributes, namespaces, and nested CDATA — eats hours that should have gone into shipping the feature.
The XML to JSON Converter at SabTools.in handles this grunt work in the browser. It uses the native DOMParser API, preserves attributes (that's the part most online converters silently drop), and runs entirely client-side so you can paste a GSTR-1 response or a Razorpay settlement XML without wondering whether your data is being logged on someone's server. Here's how to use it well, where it fits in a real Indian dev workflow, and the edge cases that trip people up.
Why XML still refuses to die in Indian enterprise
Despite JSON eating the API world after 2015, XML is deeply embedded in Indian systems that handle money, identity, and compliance:
- GSTN APIs — The e-invoice IRN generation and GSTR filing endpoints historically returned XML payloads, and many ERP integrators still parse legacy XML responses when reconciling B2B invoices.
- NSDL and UTIITSL — PAN verification, TIN-FC uploads, and NSDL CAS (Consolidated Account Statement) files are XML-first.
- SAP ecosystems — Every large Indian SI (TCS, Wipro, Infosys, HCL) runs SAP projects where IDocs, SOAP endpoints, and CPI (Cloud Platform Integration) iFlows are XML throughout.
- Banking and NPCI — ISO 20022 messages for NEFT/RTGS reconciliation, SBI and HDFC corporate banking file formats, and several UPI switch logs still arrive as XML.
- RBI reporting — XBRL (an XML dialect) is mandatory for scheduled commercial banks filing supervisory returns.
A developer at a Bangalore fintech might get a 2 MB XML dump from an IRDAI partner at 11 PM on a Tuesday, need to extract 47 policy records into a Postgres table by morning, and have no appetite for writing a custom parser. Paste, convert, pipe into a JSON validator to confirm structure, and you're querying with jq in five minutes.
How the converter actually works under the hood
The tool uses the browser's built-in DOMParser — the same engine Chrome and Firefox use to parse HTML — to build a DOM tree from your XML, then walks it recursively to produce a JSON structure. Because it runs in your tab, nothing is uploaded. For a developer at Zerodha or Razorpay handling customer PII or transaction payloads, that matters: no XML containing a customer's PAN or UPI VPA leaves the laptop.
The conversion follows a predictable set of rules:
- Element names become JSON keys. A
<invoice>element becomes aninvoicekey. - Text content becomes string values. Numbers like
<amount>49999.00</amount>remain strings — XML is typeless, so the converter doesn't guess. You cast in your downstream code. - Attributes are preserved under an
@attributeskey (or similar prefix). This is the critical bit — a GST invoice XML like<Item sl="1" hsn="998314">loses theslandhsnvalues in lazy converters, which is catastrophic when you're reconciling line items. - Repeated siblings become arrays. Three
<LineItem>children under<Invoice>collapse into aLineItem: [...]array automatically. - Namespaces are flattened into the key name (
ns2:Address→"ns2:Address"), which keeps the output valid even for SOAP envelopes.
A concrete GST e-invoice example
Say you receive this fragment from a GSTN sandbox response:
<Invoice irn="35e4bf..." version="1.1">
<Seller gstin="29ABCDE1234F1Z5">
<LegalName>Acme Traders Pvt Ltd</LegalName>
<State>Karnataka</State>
</Seller>
<LineItem sl="1" hsn="998314">
<Qty>2</Qty>
<UnitPrice>24999.00</UnitPrice>
</LineItem>
<LineItem sl="2" hsn="852872">
<Qty>1</Qty>
<UnitPrice>89990.00</UnitPrice>
</LineItem>
</Invoice>
After conversion, you get a JSON object where Invoice.LineItem is a two-element array, each with its @attributes.sl and @attributes.hsn intact. You can now loop through the items, multiply Qty × UnitPrice (₹1,39,988 total before tax), apply 18% IGST via the GST Calculator to confirm your math, and push the reconciled record into your ledger. The whole exercise takes less than ten minutes instead of the forty you'd spend writing XPath selectors in Python.
XML to JSON converter in SAP CPI — a specific note
If you're a SAP CPI developer at an Indian service company, you already know CPI ships with an XML to JSON Converter step inside iFlows. The question is: why would you also want a browser-based tool?
Three reasons come up constantly in real projects:
- Local prototyping before deploying the iFlow. You get a sample payload from the SuccessFactors or Ariba side, want to see how it'll look after conversion, but don't want to burn a cycle redeploying the iFlow just to inspect the shape. Paste the XML locally, see the JSON instantly, then configure the CPI step with correct keys.
- Debugging CPI output. CPI's conversion rules differ subtly from vanilla
DOMParser— especially around<root>handling and thejsonRootElementNameparameter. Running both and diffing them tells you whether a bug lives in the iFlow or in the downstream consumer. - Pre-flight validation. If a client sends a SOAP response via email asking "can you handle this?", you don't need to spin up a CPI tenant. Convert in-browser, validate, and respond.
The browser tool won't replace CPI for production message routing, but it's a far faster feedback loop for the ten micro-decisions you make while designing an iFlow — the kind of decisions that otherwise require a round-trip through Eclipse Adapter Design or the Web UI.
Attribute handling: the detail that matters most
Most "online XML to JSON" tools either drop attributes entirely or merge them awkwardly with child elements, which breaks any schema that depends on attribute values. Consider a Razorpay settlement notification where each payout line looks like <Payout id="pout_MkA1..." status="processed">. If the id and status attributes vanish during conversion, you've lost both your primary key and the only field that tells you whether to credit the merchant's dashboard.
The SabTools converter keeps attributes under a dedicated key so you can access them predictably: payload.Payout[0]["@attributes"].id. If you prefer a different attribute prefix (some teams use $ or _attr to match xml2js conventions from their Node backend), do a global find-and-replace on the output string before parsing. Takes two seconds.
One more gotcha for Indian payloads: the GSTIN (15 characters, like 29ABCDE1234F1Z5) often sits as an attribute on seller/buyer nodes. Verify after conversion that the GSTIN hasn't been coerced into any numeric type — it's always a string, and losing the leading state code (29 for Karnataka, 27 for Maharashtra, 07 for Delhi, 24 for Gujarat) breaks every downstream lookup.
Real workflows for the Indian dev community
A few patterns I've seen work well across CodeChef meetups, Smart India Hackathon teams, and startup engineering channels:
1. Hackathon payload prototyping
Smart India Hackathon problem statements from banks (Union Bank, Bank of Baroda) often ship with sample XML datasets. Teams who convert the XML to JSON on day one and work from the JSON for the rest of the hackathon ship cleaner demos. The judges don't care which format you parsed — they care about what the app does.
2. Legacy API wrapper services
A freelancer in Jaipur building a Flask microservice that wraps an old PAN-verification SOAP endpoint can prototype the response transformation in-browser, nail the JSON shape, and only then write the Python xmltodict code. You save at least a round of trial-and-error.
3. Postman collection cleanup
When your team imports a vendor's XML-based Postman collection, half the responses need to be converted to JSON for the frontend team to consume. Convert each sample response, store it as a mock JSON, and the React or Flutter dev at the other end doesn't need to touch XML at all.
4. Encoding and URL-safe payloads
When you need to embed a short XML snippet in a webhook callback URL for debugging, convert it to JSON first (smaller, cleaner), then pass it through a URL encoder so special characters don't break the query string. This is a surprisingly common pattern when testing Razorpay or PayU callback URLs locally with ngrok.
Edge cases that will bite you
A few quirks worth internalising before you push converted JSON to production:
- Mixed content. XML allows text and child elements to intermix:
<note>Dear <name>Riya</name>, your SIP of ₹10,000...</note>. JSON doesn't have a natural representation for this. The converter will keep the child element but you'll lose the text ordering. For transactional data this is almost never a problem; for marketing XML it can be. - CDATA sections are flattened to plain strings. If your XML uses CDATA to wrap HTML (common in CMS exports from WordPress-based Indian news sites), the HTML comes through as a string. You might then want to run it through an HTML-to-Markdown converter if you're migrating content.
- Empty elements.
<MiddleName/>becomes"MiddleName": ""ornulldepending on the implementation. Decide what your schema expects and normalise early. - Large files. The browser-based approach is fine for payloads up to roughly 5–10 MB. For 50 MB RBI XBRL filings, switch to a streaming parser in Node.js —
saxorfast-xml-parserare solid picks. - Order-sensitive siblings. JSON objects don't guarantee key order; arrays do. If your downstream consumer cares about the order of
<LineItem>s (for invoice reconciliation, it does), rely on the array structure, never on object key iteration order.
After conversion: validating the output
Converting isn't the end of the pipeline. Two quick checks save hours:
- Validate the JSON structure. Paste the output into the JSON Validator to catch any malformed output and get a quick summary of key counts, depth, and array sizes. For a GST invoice with 100 line items, confirming the array length matches your expectation is a 3-second sanity check that catches silent data loss.
- Spot-check numeric fields. Remember, all XML text comes through as strings. If you're going to total up invoice amounts, cast explicitly —
parseFloatin JavaScript,Decimalin Python. For a ₹10,00,000 payout, floating-point error accumulated across 500 line items can leave you ₹2 short on reconciliation, and your finance team will not find it funny.
When XML to JSON is the wrong move
Not every XML-to-JSON conversion is a good idea. A few cases where you should pause:
- Digitally signed XML (XMLDSig). Converting to JSON breaks the signature. If you're handling signed GSTN e-invoices or NSDL CAS files, keep the signed XML as-is for audit purposes and only convert a copy for internal processing.
- XSD-validated schemas. If your consumer validates against an XSD, converting round-trips won't match the original byte-for-byte. Store the original.
- XSLT pipelines. If there's already an XSLT transformation downstream, intercepting it with JSON conversion just adds a format hop. Leave it alone.
Pairing with other developer tools
XML conversion rarely stands alone. In a typical build pipeline for an Indian SaaS product — think a Chennai-based B2B billing startup — the converter sits next to half a dozen other utilities. You might encode a URL parameter before firing a test request, generate a Tailwind component for the admin dashboard that renders the converted data, and run percentage calculations on the parsed numbers for an analytics preview. Having these in one tab, loading in under a second even on a patchy 4G connection in a Pune co-working space, matters more than any of them being individually fancy.
Quick FAQ
Does this converter handle SOAP envelopes?
Yes. SOAP is just XML with a specific envelope structure. The namespaces (soap:Envelope, soap:Body) are preserved as string keys. You'll typically drill into Envelope.Body to get to the actual payload.
Can I convert XML with Devanagari or Tamil text?
Yes — the converter is Unicode-safe. Hindi, Tamil, Bengali, Marathi text in XML elements comes through as proper UTF-8 JSON strings. Useful when parsing Aadhaar demographic responses or multilingual GSTN templates.
Why does my numeric field show up as a string in the JSON output?
XML is typeless by design — <amount>49999.00</amount> is literally the text "49999.00". JSON converters that auto-cast numbers can silently corrupt GSTIN codes (which start with digits but must stay strings) or PAN numbers. The safer default is to keep everything as strings and cast on the consumer side.
Can I do the reverse — JSON back to XML?
That's a separate workflow. XML-from-JSON requires decisions about which keys become attributes vs child elements, root element name, and namespace handling — all things the forward conversion captures but the reverse has to guess.
Paste your XML, keep an eye on the attributes, and verify the output against your schema before shipping. Open the XML to JSON Converter →