XML to JSON Converter
Paste your XML below to convert it to JSON.
Result
How it is calculated
The tool parses the XML you paste and rebuilds its tree as indented JSON. The root element's name is reported separately and is not a key in the JSON, which starts with the root's contents. Attributes go into an "@attributes" object. An element with children becomes an object keyed by child name. When the same name repeats, the values become an array, and repeats are grouped together even if other elements sit between them. An element with only text becomes a string (leaving numbers and true/false as strings), and an empty element becomes []. Text mixed with attributes or children goes under "#text". CDATA is treated as text and comments are dropped. Namespaced names keep their prefix. The node count is the number of elements. Invalid XML gives no result.
Worked example
Paste <order id="17"><item>Pen</item><item>Ink</item></order>. The root is order, and the tool counts one order element and two item elements, so the node count is 3. The attribute id="17" becomes "@attributes": {"id": "17"}. The two item elements share a name, so they become the array "item": ["Pen", "Ink"]. The order tag itself is not a key. With only one item, the same field would be a plain string "item": "Pen" instead of an array.
Common mistakes
- Expecting the root tag as the top-level key. The output starts with the root's contents; the root name is only shown in the root field, so add it back if the JSON consumer needs it.
- Assuming a repeated element is always an array. One
<item>becomes a string or object, two or more become an array, so code reading the result must handle both. - Expecting numbers and booleans. Every value comes out as a string, so
<qty>007</qty>becomes "007", with its leading zeros kept. - Relying on the original order of mixed elements. Same-named siblings are grouped, so b, c, b comes out as b: [first, second], c.
- Pasting broken XML: an unclosed tag, an unescaped & or two root elements. The parser gives no result rather than a partial one, so fix the markup first.
About this calculator
XML and JSON are both structured, human-readable data formats, but they organize information differently — XML uses nested tags and attributes, while JSON uses nested objects, arrays, and key-value pairs — so translating between them by hand is tedious and error-prone. This converter parses any XML document, walks its element tree, and rebuilds it as clean, pretty-printed JSON, reporting the root element name and an approximate node count along the way.
The conversion is a routine step for developers integrating legacy or third-party systems — many older APIs, RSS/Atom feeds, SOAP services, and enterprise systems still speak XML, while most modern web and mobile apps consume JSON — so converting a sample response is often the fastest way to sketch out a JSON schema, test a new endpoint, or feed XML data into a JavaScript front end.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
Because repeated tag names are grouped into one array, the order in which different tags were interleaved is not kept. That is harmless for records and feeds, but documents where sequence matters, such as marked-up text or step lists mixing tag types, will not round-trip back to the original XML. Also remember that every leaf value stays a string, so cast numbers and booleans in your own code. What kind of XML are you converting, a feed, a config file or an API response?