An XML export can be hard to use in a workflow that expects JSON. It may describe a catalog, a list of events, or a paragraph with text on either side of an inline element. Before converting it, decide whether you need to preserve the XML structure or extract only a few business fields. That choice determines how you will use the result.
TinyToolbox XML to JSON represents each XML element as a JSON object with its name, any attributes, and an ordered list of children. This gives you a predictable way to inspect the XML hierarchy and reuse its values. If your application expects a custom structure such as an array of event records, use the tree as the starting point for that separate mapping.
Prepare a well-formed XML document
Copy one XML document with a single root element. An export may start with an XML declaration and then a root such as catalog. Inside that root, check that tags close in the correct order and that names match exactly. XML element names are case-sensitive. An opening Item tag and a closing item tag fail to form a matching pair.
If you copied several sibling elements on their own, wrap them in an appropriate root for an inspection copy. For example, two standalone item elements can sit within a catalog element. Keep the original export if an upstream service expects its specific structure or namespace declarations.
The tool rejects XML containing a document type declaration. If your source has one, obtain an export that does not require it or prepare a self-contained XML sample. Simply deleting a declaration can leave references to entities that are no longer defined. If those references appear in the actual document, resolve them with an authorized workflow that understands the source before attempting this conversion.
A successful parse establishes that the parser can read the XML. It does not check an XML schema, required attributes, or whether values meet an application’s rules. A price can appear as an element in well-formed XML even if it uses a format the receiving system will reject.
Run XML to JSON in TinyToolbox
- Open XML to JSON Converter.
- Paste the source markup into XML.
- Select Run tool.
- Inspect the tree-shaped JSON under Result.
- Select Copy result if you want to paste it into an editor or another tool.
The conversion runs in your browser. If you copy an example from documentation, leave out code fences and surrounding explanation. For a large source, start with a representative section that forms a complete XML document on its own. Include the namespace declarations needed by that section. A sample with one parent, two repeated elements, and a few attributes can show whether the output has the properties your workflow needs.
If you only want to see the hierarchy without converting it, XML Tree Viewer offers an indented view. If you need to work with the copied JSON, JSON Formatter & Viewer can display it as expandable arrays and objects.
Read the name, attributes, and children
Consider a compact XML catalog with two entries. It is written on one line here so there are no extra indentation strings between the items.
<catalog region="north"><item code="001">Notebook</item><item code="002">Pencil</item></catalog>
The converter produces the following shape:
{
"name": "catalog",
"attributes": {
"region": "north"
},
"children": [
{
"name": "item",
"attributes": {
"code": "001"
},
"children": ["Notebook"]
},
{
"name": "item",
"attributes": {
"code": "002"
},
"children": ["Pencil"]
}
]
}
The top-level JSON object represents catalog. It is not a wrapper with a property named catalog. Both item elements have their own object inside children, in the same sequence as the source. The code values remain strings, so their leading zeros stay visible. A node with no attributes omits the attributes property. An empty element has an empty children array.
The same structure supports a document containing multiple element names at one level. A heading, two item elements, and a note can appear in that order in one array. If you need only items later, select children whose objects have the name item. That selection is a choice your application makes after conversion.
Account for whitespace and mixed content
Indenting XML can put newline and space characters between elements. The converter carries through text nodes, including that whitespace. A pretty-printed catalog may therefore produce string entries between the item objects. When inspecting a data-only export, you can ignore whitespace-only children where you know they are just layout. Keep the source when whitespace itself matters.
Consider this inline example:
<message>Bring a <em>small</em> notebook.</message>
The children array contains three entries in order: the string Bring a ** with its trailing space, the em element with small inside it, and the string ** notebook. with an initial space. It is possible to reconstruct the reading order from that array. Removing all leading and trailing spaces from every string would join the words incorrectly.
A CDATA section is carried as text. Ordinary entity references that the XML parser resolves also appear as character values. For example, & in source markup represents an ampersand in the parsed text. This helps an application use the value, but it means the JSON cannot show whether the original author used a CDATA section or a particular escape. Comments and processing instructions are omitted from the tree. Retain the original XML if you need those details.
Handle prefixed names and string values deliberately
An XML feed may use names such as media:title. The tree reports the element name including the prefix. The converter does not change it into the property title or supply a separate normalized namespace identifier for every node. Namespace declarations can appear as attributes on elements that declare them. Preserve those declarations and keep the surrounding context if your downstream workflow needs to resolve qualified names.
The same local name can occur with two different prefixes that identify different vocabularies. When mapping a feed, identify which elements your receiving application actually expects before combining them. Removing all prefixes can make two distinct entries look the same. Conversely, two producers may use different prefixes for the same namespace. Use an XML- or namespace-aware mapping when that distinction matters.
Text and attribute values stay strings. If an attribute says enabled=“false”, the JSON attribute contains the string “false”. A numeric-looking code such as 001 also remains a string. Apply type conversions based on the destination’s schema. A product code can require leading zeros even when a quantity in a neighboring field should be a number.
Adapt the tree to a downstream format
Suppose a system wants a JSON array of records with a code and label. The catalog example gives you both values, but it still encodes them within an XML-shaped tree. Select the item objects in the catalog’s children, read their code attributes, and collect their text as labels according to the rules of that catalog. Decide what to do with an empty label, a missing code, or an item containing additional inline elements.
Check repeated elements with realistic examples. A single-item sample can hide an issue when the actual export contains two or more records. Test a sample with repeated items, a missing optional attribute, and a label with characters that need XML escaping. Compare output with the source and confirm the receiving format preserves the values you need.
If you want to turn a structural tree back into markup, JSON to XML can work with supported tree nodes. Treat the result as a new serialization and verify it against the intended document. The source formatting, comments, XML declaration, and spelling of escaped text can differ.
Compare two exports that look almost identical
Imagine a catalog is exported once a week. Both exports contain the same opening tag and familiar records, but the newer one places two entries in a different order and adds a note between them. If the downstream catalog shows items in source order, check the positions of those objects in the children array. The note will have its own position between the item nodes, and it should remain there if it applies to the item immediately before it.
Create a small example from each version and convert both. Open the results in JSON Difference Checker with the older export first. The checker compares array entries by position, so a new child can produce multiple positional changes. Use the report to locate the affected part, then return to the source XML to see whether the entries moved or their values changed. A pretty-printed revision can also introduce whitespace strings into the array, which may alter positions without changing the order of the elements.
If your application only shows catalog items, compare the mapped item records as a separate check. That check is useful for understanding what readers see, while the original tree is still useful for diagnosing changes to notes, namespaces, and other parts that the mapping intentionally excludes.
Diagnose an input error and verify the result
If the tool reports malformed XML, look for multiple roots, mismatched tags, unquoted attribute values, and literal ampersands in text. If the issue began when you copied a fragment from a feed, make sure it still has the declarations it needs. Test the smallest complete sample that reproduces the failure so you can see which part of the markup needs attention.
After successful conversion, inspect the root name, count the repeated elements you care about, and verify representative attributes and text values. Check at least one case with a namespace, an empty element, or whitespace that matters if your source includes those features. Save the original alongside the derived JSON so you can trace any later mapping questions to the exact XML you started with.
Check repeated elements with an empty item and a zero value
Suppose you need to inspect three stock entries from a small XML export. Paste this complete example into XML to JSON.
<stock>
<item code="0007"><quantity>0</quantity></item>
<item code="0018"><quantity/></item>
<item code="0042"/>
</stock>
Find the three child objects named item under stock, ignoring indentation-only strings for this particular count. Each item’s code attribute preserves the leading zeros. The first item contains a quantity element with the text string “0” as its child. The second contains an empty quantity element. The third has no quantity element. Check each representation separately before mapping the tree into records.
In a downstream inventory file, zero could stand for a confirmed absence of stock. An empty element or missing element may have another meaning according to the export contract. Some applications treat both as unknown, while others distinguish a deliberately empty element from a field that was never sent. The conversion preserves those structural differences and leaves any interpretation to the next step. Keep the item code attached to the quantity so that filtering whitespace or extracting child nodes does not shift one record’s value onto another.
Before relying on the mapped data, compare the three output rows with the original example. Check that the first quantity is represented as the intended numeric zero if the destination expects a number, that the two other states follow the destination’s rules, and that the identifiers remain text. Repeat the test with two items in a different order if your application uses order or looks up records by code. A small fixture makes it possible to see whether a change in an XML feed altered the structure or only the position of a record.