XML转JSON

解析 XML 文档为等价的 JSON 对象。

xml解析
关于「XML转JSON」

它属于「JSON 工具」分类:JSON 的格式化、结构变换与各种数据格式互转。

  • 使用浏览器内置的 <code>DOMParser</code> 解析,遵循标准 XML 规范。
  • 元素的<b>属性</b>会转成带前缀的键,例如 <code>id="1"</code> → <code>"@id": "1"</code>。
  • 同名的兄弟标签会自动<b>合并为数组</b>,单个则保持对象形式。
  • 只有文本内容、没有属性和子元素的节点,会直接简化为字符串。
  • 解析失败时会提示具体的错误原因,便于定位标签未闭合等问题。

完全免费、无需注册;所有处理都在浏览器本地完成,文件不会上传到任何服务器。

相关关键词:XML转JSON、JSON 工具、xml、解析、在线工具、免费

如何使用「XML转JSON」
  1. 打开工具:打开「XML转JSON」页面,无需注册、无需安装任何软件。
  2. 准备输入:准备好要处理的内容或文件:文本可直接粘贴,文件可拖入页面(本工具属于「JSON 工具」)。
  3. 填入内容:把内容粘贴进输入框,或把文件拖入页面;也可以点击「示例」先填入样例数据试一下。
  4. 设置选项并处理:按需调整页面上的选项,然后点击处理 / 转换 / 生成按钮。
  5. 获取结果:处理完全在浏览器本地完成,结果可直接复制或下载,文件不会上传到任何服务器。
常见问题
属性前缀可以改吗?
可以,把前缀改成 <code>$</code>、<code>_</code> 或留空都行。留空时要注意属性名可能与子标签名冲突而互相覆盖。
为什么有的节点是字符串,有的是对象?
为了让结果更简洁:如果一个节点既没有属性也没有子元素,就直接用它的文本值表示;只要存在属性或子元素,就必须用对象来承载。
同名标签只有一个时也是数组吗?
不是。只出现一次时保持对象或字符串形式。如果你的代码需要稳定的数组类型,记得在读取时做一次兼容判断。
提示解析失败怎么办?
通常是 XML 本身不合法,比如标签没有闭合、存在多个根节点,或含有未转义的 <code>&amp;</code> 符号。请按提示信息检查源文档。
XML to JSON (English)

Parse an XML document into an equivalent JSON object.

Belongs to “JSON Tools”: Format, transform and convert JSON to and from various data formats.

  • Parsed with the browser’s built-in <code>DOMParser</code>, following standard XML rules.
  • Element <b>attributes</b> become prefixed keys, e.g. <code>id="1"</code> → <code>"@id": "1"</code>.
  • Sibling tags with the same name auto-<b>merge into an array</b>; a single one stays an object.
  • A node with only text and no attributes or children collapses to a plain string.
  • On failure it reports the specific reason, helping locate unclosed tags, etc.

Free, no sign-up; everything runs locally in your browser and files are never uploaded.

Keywords: XML to JSON, JSON Tools, xml, parse, online tool, free

How to use it

  1. Open the tool:Open the “XML to JSON” page — no sign-up and nothing to install.
  2. Prepare the input:Prepare the content or file to process: paste text or drop a file onto the page (this tool belongs to “JSON Tools”).
  3. Provide the input:Paste your content into the input box or drop a file onto the page; you can also click “Sample” to try example data first.
  4. Adjust options and run:Adjust the options if needed, then click the process / convert / generate button.
  5. Get the result:Everything runs locally in your browser; copy or download the result — your files are never uploaded.

FAQ

Can the attribute prefix change?
Yes — change it to <code>$</code>, <code>_</code> or leave it empty. If empty, an attribute name may collide with and overwrite a child tag.
Why are some nodes strings and others objects?
To keep results compact: a node with neither attributes nor children becomes its text value; once attributes or children exist, an object is required.
Is a single same-named tag also an array?
No. A single occurrence stays an object or string. If your code needs a stable array type, add a guard when reading.
Parse failed — what now?
Usually the XML is invalid — unclosed tags, multiple roots, or an unescaped <code>&amp;</code>. Check the source per the message.

More tools in JSON Tools

  • JSON Formatter/Minifier — Beautify, minify, validate and highlight JSON.
  • Sort JSON Keys — Recursively sort object keys alphabetically to ease diffing.
  • Flatten JSON — Flatten nested structures into a.b.c single-level keys.
  • Unflatten JSON — Restore dotted-path objects into nested structures.
  • JSON to CSV — Convert an array of objects into a downloadable CSV.
  • CSV to JSON — Parse CSV text or files into a JSON array.
  • JSON to Excel — Export an array of objects as an .xlsx workbook.
  • Excel to JSON — Upload an Excel file and convert sheets to JSON.
  • JSON to XML — Convert JSON structures into well-indented XML.
  • JSON to YAML — Convert JSON into more readable YAML.
  • YAML to JSON — Parse YAML config into standard JSON.
  • JSON to SQL — Generate INSERT statements and CREATE TABLE DDL from arrays.
  • SQL to JSON — Reverse-engineer JSON data from INSERT statements.
  • JSON to Base64 — Convert JSON to and from Base64 with UTF-8 support.
  • JSON ⇄ Cookie — Convert between Cookie strings and JSON key-values.
  • JSON Diff — Recursively compare two JSON documents, marking add/delete/change.

返回崽崽工具箱首页