Generally an XML-to-JSON library is going to assume that the data in the XML file is represented using normal XML conventions, that is, it will not contain JSON-style escape sequences. So it will assume that \"
in the XML represents backslash followed by quotation mark, which is represented in JSON as \\\"
.
If you would like to consider using the xml-to-json()
function in XPath 3.1, it has an option to mark the input XML with escaped="true"
to indicate that JSON escape sequences are present in the XML. There are of course many other XML-to-JSON conversion libraries available, all with their own quirks, conventions, and restrictions.