Markdown 转 JSON AST

把 Markdown 解析成带类型、层级和内容的 JSON 抽象语法树,而不是把整篇文字简单塞进一个 JSON 字段。

Markdown 输入

86 字符

JSON 预览

转换后的文字
[
  {
    "type": "heading",
    "children": [
      {
        "type": "inline",
        "content": "项目笔记",
        "children": [
          {
            "type": "text",
            "content": "项目笔记"
          }
        ]
      }
    ],
    "tag": "h1"
  },
  {
    "type": "paragraph",
    "children": [
      {
        "type": "inline",
        "content": "清晰的文档从**明确的结构**开始。",
        "children": [
          {
            "type": "text",
            "content": "清晰的文档从"
          },
          {
            "type": "strong_open",
            "tag": "strong"
          },
          {
            "type": "text",
            "content": "明确的结构"
          },
          {
            "type": "strong_close",
            "tag": "strong"
          },
          {
            "type": "text",
            "content": "开始。"
          }
        ]
      }
    ],
    "tag": "p"
  },
  {
    "type": "heading",
    "children": [
      {
        "type": "inline",
        "content": "检查重点",
        "children": [
          {
            "type": "text",
            "content": "检查重点"
          }
        ]
      }
    ],
    "tag": "h2"
  },
  {
    "type": "bullet_list",
    "children": [
      {
        "type": "list_item",
        "children": [
          {
            "type": "paragraph",
            "children": [
              {
                "type": "inline",
                "content": "层级清楚的标题",
                "children": [
                  {
                    "type": "text",
                    "content": "层级清楚的标题"
                  }
                ]
              }
            ],
            "tag": "p"
          }
        ],
        "tag": "li"
      },
      {
        "type": "list_item",
        "children": [
          {
            "type": "paragraph",
            "children": [
              {
                "type": "inline",
                "content": "可以正常打开的链接",
                "children": [
                  {
                    "type": "text",
                    "content": "可以正常打开的链接"
                  }
                ]
              }
            ],
            "tag": "p"
          }
        ],
        "tag": "li"
      },
      {
        "type": "list_item",
        "children": [
          {
            "type": "paragraph",
            "children": [
              {
                "type": "inline",
                "content": "便于继续编辑的文件",
                "children": [
                  {
                    "type": "text",
                    "content": "便于继续编辑的文件"
                  }
                ]
              }
            ],
            "tag": "p"
          }
        ],
        "tag": "li"
      }
    ],
    "tag": "ul"
  },
  {
    "type": "blockquote",
    "children": [
      {
        "type": "paragraph",
        "children": [
          {
            "type": "inline",
            "content": "下载前先检查渲染预览。",
            "children": [
              {
                "type": "text",
                "content": "下载前先检查渲染预览。"
              }
            ]
          }
        ],
        "tag": "p"
      }
    ],
    "tag": "blockquote"
  }
]
文件在当前浏览器标签页中处理。

如何解析 Markdown AST

输入变化后,JSON 节点结构会随之更新。

01

输入 Markdown

加入需要分析的文档或最小复现片段。

02

检查节点层级

展开标题、段落、列表、链接、代码等节点,确认父子关系。

03

复制或下载 JSON

将 AST 用于调试、转换管线或自定义渲染。

不是普通文本封装

查看 Markdown 被解析后的文档树

AST 让程序能够按结构处理文档。

节点类型区分标题、文本、强调、链接、列表、代码等语义。
嵌套层级保留列表和块级元素的父子关系。
可复制 JSON便于在测试、构建脚本或可视化工具中继续处理。
开发用途

需要程序理解 Markdown 时

解析器调试

定位某段语法为什么没有按预期渲染。

自定义转换

从 AST 生成内部数据结构、索引或其他标记语言。

结构差异比较

比较两个文档的节点变化,而不只看原始字符 diff。

常见问题

Markdown 转 JSON 常见问题

输出是 Markdown 的 JSON 版本吗?

更准确地说是解析后的 AST,JSON 用来表示文档节点、属性和层级。

可以直接把 JSON 再转回完全相同的 Markdown 吗?

AST 保留语义结构,但空白、标记选择等源代码细节可能不会逐字符还原。

适合做 API 数据吗?

可以作为开发管线的一部分,但正式接口应固定并记录 schema,而不是依赖页面内部实现长期不变。