QCSunny Lab

XML ⇄ JSON ConverterXML 与 JSON 互转工具

Output转换输出

Convert XML to JSON and back using the classic xml2js convention: attributes become "@key" entries, mixed text becomes "#text", and repeated elements become JSON arrays. A single text-only child collapses to a plain string.

The parser handles comments, CDATA sections, entity references and processing instructions locally in your browser — no server round trip.

Frequently asked questions

Is the JSON → XML conversion lossless?

Round trips are lossless for elements, attributes and text. Namespace prefixes (like soap:) are kept verbatim as part of the tag name, not expanded.

What JSON converts to XML?

The root must be an object with exactly one key — it becomes the root element. Nested objects become child elements, arrays become repeated elements, and "@key" / "#text" entries become attributes / text.

中文说明

按经典的 xml2js 约定实现 XML 与 JSON 双向互转:属性映射为 "@键"、混排文本为 "#text"、重复元素合并为数组,纯文本子元素直接折叠为字符串。

解析器支持注释、CDATA 节、实体引用与处理指令,全部在浏览器本地完成,不经服务器。

常见问题

JSON 转 XML 是无损的吗?

元素、属性与文本往返无损。命名空间前缀(如 soap:)作为标签名的一部分原样保留,不做展开。

什么样的 JSON 能转 XML?

根必须是恰好一个键的对象——它就是根元素。嵌套对象变成子元素、数组变成重复元素,"@键" 与 "#text" 分别映射为属性与文本。