w

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

  1. Click in the XML Input text area
  2. Type or paste your XML content
  3. The conversion will happen automatically as you type

Load Sample Data

  1. Click the Load Sample button to see an example
  2. This will populate the input area with sample XML data
  3. 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

  1. Click the Copy button
  2. The JSON is copied to your clipboard
  3. Paste it into your application or editor

Download as File

  1. Click the Download button
  2. A JSON file will be downloaded to your computer
  3. 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

  1. Validate XML first: Ensure your XML is well-formed
  2. Use consistent formatting: Properly indented XML is easier to work with
  3. Test with sample data: Use the sample data to understand the conversion process
  4. Check the output: Review the JSON to ensure it meets your needs
  5. Save your work: Use the history feature to keep track of conversions
Was this page helpful?