Using the XML to JSON Converter
This page turns one XML element into JSON. It parses the text first. A note whose children are to and body becomes {"to":"Ada","body":"Hello"}. The root name is reported on its own line. The children become the keys of the JSON object. The headline is the character count of that JSON. Copy returns the JSON itself, not the count.
The page does not fetch a URL. It does not accept a document type declaration or an entity declaration. Broken markup is rejected rather than repaired. You can paste up to 20,000 characters. Attributes are grouped under the key @attributes. When an element has both attributes and text, the text can appear under the key 0. That is the shape this parser writes. It is not a second dialect you can switch off.
The sample root line says note. The JSON does not wrap itself in a note key. If you need the root name inside the JSON, this page will not add it. The root line is where that name remains visible.
What the JSON Contains
Child elements become keys, and their text becomes values. In the sample, to is Ada and body is Hello. There are no extra spaces. The character count in the headline includes the braces, the quotes, the colon, and the comma. Copy uses the compact text under the headline.
A root with no children can still be valid XML. What the JSON looks like then depends on whether the element is empty or holds text. Read the result rather than assuming a wrapper. The page shows the JSON it produced. It does not offer a second layout.
Reset returns the field to the note sample. The previous JSON stays on screen until you convert again. Copy it if you still need it.
How the Element Is Read
The text is trimmed, checked for a document type or an entity declaration, and then parsed as one element. Network access is not used. A parse failure becomes the message "Enter valid XML." The page does not point at a line number. If you need a line number, use a checker that reports one, then come back with markup that already parses.
After a successful parse, the element is written as JSON with slashes and non-ASCII characters left unescaped. The root element's own name is not a JSON key. It is the root line beside the character counts.
Removing line breaks from prose is a different cleanup. The Remove Line Breaks tool joins lines of text. It does not parse tags. Use it for a paragraph. Use this page when the text is supposed to be one XML element.
What the Parser Will Not Fix
A missing close tag is not inserted. A bare < is rejected. Two roots side by side, with no parent, are not one element and are rejected. The page will not wrap them for you. Wrap them in one parent if that is the document you meant, and convert the parent.
Comments and a document type are not kept as JSON keys. A document type is rejected before parsing so the page does not follow an external declaration. Take the declaration out if the element itself is what you wanted to convert. An entity declaration is rejected for the same reason.
The 20,000 character cap is on the XML you paste, not on the JSON. A failure that names the cap is not a syntax error. Shorten the paste. A failure that says to enter valid XML is syntax, and shortening it will not help until the tags match.
Worked Elements
Paste <note><to>Ada</to><body>Hello</body></note>. The JSON text is {"to":"Ada","body":"Hello"}. The root line is note. Paste an element that does not parse, such as a single opening angle bracket. The page rejects it and does not leave a previous JSON in place as if the new paste had succeeded. Calculate again after you fix the markup.
Paste a document type in front of a note. The page rejects it even if the note element would have parsed alone. Remove the declaration and convert the element. That split is deliberate. The declaration is not ignored. It is refused.
Minifying JSON you already have is a different page. The JSON Minifier parses JSON and writes it without extra space. It does not read tags. Use it when the text is already JSON. Use this page when the text is XML and you want JSON.
Limits of This Shape
Attributes and text share an element in a way that JSON objects do not. This page puts attributes under @attributes. Text in that same element can use the key 0. A converter with a different convention might name that text #text. This page does not. If a downstream tool expects #text, you will need to rename the key yourself. The article states the keys this parser writes so the rename is a conscious step.
Repeated child names can collapse in the JSON object because object keys are unique. Two <item> children may not survive as two keys named item. If your document depends on repeated names, look at the JSON before you trust a count of items. The page will not switch to an array of pairs to preserve duplicates.
Namespaces and prefixes are not given a special map. They are whatever the parser leaves in the element names. The page does not strip a prefix and it does not look up a schema.
Common Mistakes
The usual miss is to expect the root name inside the JSON. The sample JSON starts with to, not with note. The root line says note. Reading only the JSON and wondering where the root went is answered by that line. The page is consistent about this. It does not sometimes wrap and sometimes not.
Another miss is to paste a spreadsheet export that is not well-formed XML and hope the odd rows are skipped. They are not skipped. The whole paste fails. Fix the markup, or convert a smaller element you have checked.
Counting sentences will not tell you the tags match. The Sentence Counter counts sentences in prose. An XML element is not a sentence. Use a successful conversion here as the sign that the element parsed.
Using the JSON Afterward
Copy the JSON into the place that asked for JSON. Keep the XML if you still need the original tags. This page does not store a history. Reset brings back the sample note, not your previous paste.
Look at the first and last characters before you copy. The JSON from an element is an object, so it should start with { and end with }. A result that is on screen parsed in full. A truncated paste that lost the final tag will have been rejected.
Do not paste secrets you would not want in a result you might copy. Converting XML does not hide a password that was in a tag. The page does not look for secrets. It rewrites the structure.
Reading the Sample Character by Character
The sample JSON is {"to":"Ada","body":"Hello"}. It opens with a brace. The key to is quoted. A colon follows. Ada is a quoted string. A comma separates the next key, body, and the string Hello. The brace closes. There is no space. The headline count matches those characters. If you insert a space by hand, you no longer have the page's output.
The root line for that paste is the word note. It is not inside the braces. A test of the page is to see both: the JSON without a note key, and the root line that still says note. If the JSON suddenly wraps the children in note, the page would be doing a different conversion from the one this article describes.
Try a document type next, on purpose. The rejection should name document type and entity declarations. Then try a blank field. The message should ask you to paste an XML element. Those two sentences distinguish a forbidden declaration from an empty box. A lone angle bracket uses the valid-XML sentence instead.
Identifiers elsewhere in a system are unrelated to this rewrite. The UUID Generator draws an identifier. It does not parse tags. Use it when you need an identifier. Use the sample braces when you are checking this conversion.
After the sample matches, paste your own element and read the root line before you copy. The root line is the name the parser saw. The JSON is the children and attributes. Copy the JSON. Keep the root name in your notes if the next system needs it and this JSON does not carry it. Reset returns the sample note to the field. It does not delete a JSON you already copied out.
Checking a Paste
Confirm the sample JSON and the root word note. Confirm a document type is rejected. Confirm a blank field is a different message from a broken tag. Confirm the copy text is the JSON, while the headline is only the count.
Language links for a page are a different kind of markup. The Hreflang Generator builds link elements for language versions of a page. It does not turn XML into JSON. Use it for those links. Use the Ada sample to audit this page.
Reading the Note Sample in Detail
The sample element is a note whose children are to and body. The text values are Ada and Hello. The JSON text is {"to":"Ada","body":"Hello"}. The root line says note and is not a key inside that object. Copy returns the JSON. The headline is the character count of that JSON, not the word note and not a success banner. If you quote the result in a ticket, quote the JSON and mention the root separately. A ticket that says only "note" has the root and has lost the payload.
Checking the Calculator
Convert the note sample. Confirm the JSON is {"to":"Ada","body":"Hello"} and the root is note. Submit a document type and confirm the rejection. Submit a single opening angle bracket and confirm the valid-XML message.