360 Secure SkillHub
360 安全技能中心

Doc to JSON

该 Skill 提供一条从文档到 JSON 的转换管线:先用 mineru-open-api 把 doc、docx、PDF、xlsx、xls 提取为 Markdown,再由脚本解析为带标题层级、表格、列表和元数据的 JSON,并附知识库准备模式参考。

kounlong
kounlong
热度 32.20
最近更新 2026-05-11 17:43:59
分类:效率依赖:代码执行 / 读写文件 / 第三方 API应用场景:文件转换 / 数据处理 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add doc-to-json
Metadata
name
doc-to-json
description
Convert documents (docx, doc, PDF, xlsx, xls) to structured JSON via MinerU. Full pipeline: file to mineru-open-api extract to Markdown then to JSON. Use when user wants to convert a document to JSON, prepare files for local knowledge base RAG, extract structured data from course materials, standards, or reports. Triggers: 转JSON, 转markdown, 知识库素材, doc转json, PDF转JSON, MinerU, 文档解析, extract to json, course standard JSON.

Doc to JSON

Convert office documents to structured JSON using MinerU as the extraction engine.

Supported Formats

  • .doc / .docx — Word documents
  • .pdf — PDF files
  • .xlsx / .xls — Excel spreadsheets

Prerequisites

  • mineru-open-api CLI must be installed (v0.5+)
  • MINERU_TOKEN environment variable must be set
  • Check: mineru-open-api version

Quick Usage

# Full pipeline: document -> MinerU Markdown -> JSON
python3 scripts/doc_to_json.py /path/to/file.docx -o output.json

# Keep temp files for debugging
python3 scripts/doc_to_json.py /path/to/file.pdf -o out.json --keep-temp

Manual Two-Step Pipeline

If the full pipeline script fails, run steps manually:

Step 1: MinerU Extract

export MINERU_TOKEN="your_token"
mineru-open-api extract input_file.pdf -o /tmp/mineru_out/

Output: .md file in the output directory.

Step 2: Markdown -> JSON

python3 scripts/markdown_to_json.py /tmp/mineru_out/output.md -o output.json

JSON Structure

The output JSON preserves:

  • Metadata fields — course name, code, credits, hours, etc. (extracted from plain text)
  • Heading hierarchy — 一、二、三... sections become nested keys
  • Tables — stored as array of arrays (row cells), keyed as "表格"
  • Numbered lists — stored as array of strings under section title
  • Paragraph text — merged into "text" field per section

For Knowledge Base Preparation

After JSON conversion, common next steps:

  1. Chunk by section — split the JSON into per-section documents for embedding
  2. Table extraction — convert "表格" arrays to flattened rows for database import
  3. Metadata extraction — pull course code, name, etc. as document metadata
  4. Embedding — feed cleaned text chunks into vector database

See references/kb-prep.md for detailed KB preparation patterns.