Basic Usage
This guide will walk you through the fundamental steps of using the XML to JSON Converter effectively.
Step 1: Input Your XML Data
Manual Input
- Click in the XML Input text area
- Type or paste your XML content
- The conversion will happen automatically as you type
Load Sample Data
- Click the Load Sample button to see an example
- This will populate the input area with sample XML data
- Perfect for testing and learning the tool
Example XML Input
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book id="1" category="fiction">
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<year>1925</year>
<price>10.99</price>
</book>
<book id="2" category="non-fiction">
<title>Clean Code</title>
<author>Robert C. Martin</author>
<year>2008</year>
<price>29.99</price>
</book>
</bookstore>
Step 2: Configure Conversion Options
Pretty Print
- Enabled (default): Formats JSON with proper indentation and line breaks
- Disabled: Produces compact, minified JSON
Include Attributes
- Enabled (default): XML attributes are included as
@attributes
objects - Disabled: XML attributes are ignored in the conversion
Step 3: View the Output
The converted JSON will appear in the JSON Output area in real-time:
{
"bookstore": {
"book": [
{
"@attributes": {
"id": "1",
"category": "fiction"
},
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"year": "1925",
"price": "10.99"
},
{
"@attributes": {
"id": "2",
"category": "non-fiction"
},
"title": "Clean Code",
"author": "Robert C. Martin",
"year": "2008",
"price": "29.99"
}
]
}
}
Step 4: Use the Converted JSON
Copy to Clipboard
- Click the Copy button
- The JSON is copied to your clipboard
- Paste it into your application or editor
Download as File
- Click the Download button
- A JSON file will be downloaded to your computer
- Use the file in your projects
Understanding the Conversion
Element Structure
- XML elements become JSON objects
- Element names become JSON keys
- Text content becomes string values
Attributes
When "Include Attributes" is enabled:
- XML attributes are grouped under
@attributes
- Each attribute becomes a key-value pair
Arrays
- Multiple elements with the same name become JSON arrays
- Single elements remain as objects
Text Content
- Element text content is stored as
#text
when mixed with other content - Pure text elements become string values
Error Handling
Invalid XML
- Red error messages appear for malformed XML
- Common issues include unclosed tags, invalid characters, or syntax errors
- Fix the XML and the conversion will work automatically
Common XML Issues
- Unclosed tags:
<book>
without</book>
- Invalid characters: Special characters not properly encoded
- Malformed attributes: Missing quotes around attribute values
Tips for Best Results
- Validate XML first: Ensure your XML is well-formed
- Use consistent formatting: Properly indented XML is easier to work with
- Test with sample data: Use the sample data to understand the conversion process
- Check the output: Review the JSON to ensure it meets your needs
- Save your work: Use the history feature to keep track of conversions