How to Convert Python Dict to XML?

The key-value pair structure of a Python dict is very similar to that of XML, but there are differences in syntax and data types. If you need to visualize or process a python dict, you can first convert it to XML and then use the powerful XML editing and visualization features on XML For You. The steps are as follows:

  1. Paste the original XML string into the left editor;
  2. Click "Search Command" at the top, find "Python dict to XML", and click to execute.

Since there are significant differences between python dict and XML, XML For You currently only supports simple text replacement, so converting complex dicts may fail.

FeaturePython DictionaryXML
String QuotesSingle or double quotesDouble quotes only
Trailing CommasAllowedNot allowed
CommentsAllowed in code (not in dictionary literals)Not supported
Key TypeCan be any hashable typeString
Value TypeSupports tuples, sets, datetime, and custom objectsOnly supports strings, numbers, booleans, null, arrays, and objects

Example

Python dict:

{
    'name': 'John Doe',
    'age': 30,
    'is_student': False,
    'hobbies': ['reading', 'coding', 'hiking'],
    'address': {
        'street': '123 Main St',
        'city': 'Anytown'
    },
}

Converted XML:

{
  "name": "John Doe",
  "age": 30,
  "is_student": false,
  "hobbies": ["reading", "coding", "hiking"],
  "address": {
    "street": "123 Main St",
    "city": "Anytown"
  }
}