Convert XML documents to JSON format for modern applications
{
"catalog": {
"book": [
{
"@id": "1",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"price": 9.99
},
{
"@id": "2",
"title": 1984,
"author": "George Orwell",
"price": 12.99
}
]
}
}Elements: XML elements become JSON objects with the tag name as the key.
Attributes: XML attributes are prefixed with @ (e.g., @id, @class).
Text Content: Element text becomes the value or #text if there are also attributes.
Repeated Elements: Multiple elements with the same name become JSON arrays.