Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat: replace to_export_dict with to_dict for consistency in JSON exports

myhloli601c3e4a14b3
diff --git a/mineru/cli_old/common.py b/mineru/cli_old/common.py
index e5610487..42320f0c 100644
--- a/mineru/cli_old/common.py
+++ b/mineru/cli_old/common.py
@@ -335,7 +335,7 @@ def _process_output(
)
if f_dump_middle_json:
- dump_dict = export_result.to_export_dict()
+ dump_dict = export_result.to_dict()
dump_dict["_backend"] = backend
dump_dict["_version_name"] = __version__
md_writer.write_string(
diff --git a/mineru/doclib/services/parse_svc.py b/mineru/doclib/services/parse_svc.py
index ce62232e..851167bc 100644
--- a/mineru/doclib/services/parse_svc.py
+++ b/mineru/doclib/services/parse_svc.py
@@ -845,7 +845,7 @@ class ParseService:
return False
await self._record_execute(execute_start_ms, tier=tier, server=server_dim, status="succeeded")
- export_payload = result.to_export_dict(skip_defaults=True)
+ export_payload = result.to_dict(skip_defaults=True)
new_pages = export_payload["pages"]
if not new_pages:
await self._fail_task(task["id"], "parse_empty", "Parse completed but returned no pages")
diff --git a/mineru/kit/common.py b/mineru/kit/common.py
index 6d6d1c52..a142e233 100644
--- a/mineru/kit/common.py
+++ b/mineru/kit/common.py
@@ -147,7 +147,7 @@ def save_parse_result(result: ParseResult, dest: Path, format: KitFormat) -> Non
_write_image_sidecars(dest.parent, result.images())
return
if format == "middle_json":
- _write_utf8_text(dest, result.to_export_json())
+ _write_utf8_text(dest, result.to_json())
_write_image_sidecars(dest.parent, result.images())
return
if format == "zip":
diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.py
index 5f28ee9d..500eac6b 100644
--- a/mineru/parser/api_server.py
+++ b/mineru/parser/api_server.py
@@ -1260,7 +1260,7 @@ async def _run_job(
fid = file_store.create_file_for_output(f"{fr.name}.md", content_bytes, sha256hex=sha)
output_files.markdown = OutputFileRef(file_id=fid, bytes=len(content_bytes))
elif fmt == "middle_json":
- mj = json.dumps(result.to_export_dict(skip_defaults=True), ensure_ascii=False).encode("utf-8")
+ mj = json.dumps(result.to_dict(skip_defaults=True), ensure_ascii=False).encode("utf-8")
sha = hashlib.sha256(mj).hexdigest()
file_store.store_blob(mj, sha256hex=sha)
fid = file_store.create_file_for_output(f"{fr.name}.middle.json", mj, sha256hex=sha)
diff --git a/mineru/parser/base.py b/mineru/parser/base.py
index 523cf59d..74cefaf6 100644
--- a/mineru/parser/base.py
+++ b/mineru/parser/base.py
@@ -95,10 +95,6 @@ class ParseResult:
self._append_private_pdf_page_mapping(payload)
return payload
- def to_export_dict(self, *, skip_defaults: bool = True) -> dict[str, Any]:
- """兼容旧调用名;当前 pages 已经是 public clean middle_json。"""
- return self.to_dict(skip_defaults=skip_defaults)
-
@staticmethod
def _append_root_backend(payload: dict[str, Any], pages: list[PageInfo]) -> None:
"""在 envelope 级别保存统一 backend,避免 public page 字段暴露私有属性。"""
@@ -125,10 +121,6 @@ class ParseResult:
def to_json(self) -> str:
return json.dumps(self.to_dict(), ensure_ascii=False, indent=4)
- def to_export_json(self) -> str:
- """兼容旧调用名;当前与 to_json 输出一致。"""
- return self.to_json()
-
def _public_render_pages(self) -> list[PageInfo]:
"""返回 public 渲染页;图片载荷已在 middle_json 生成阶段外置。"""
return self.pages
@@ -144,7 +136,7 @@ class ParseResult:
def save(self, writer: Any) -> None:
writer.write_string("markdown.md", self.markdown())
- writer.write_string("middle_json.json", self.to_export_json())
+ writer.write_string("middle_json.json", self.to_json())
writer.write_string(
"content_list.json",
diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.py
index 6afdd7e2..aa1d189f 100644
--- a/tests/unittest/test_doclib_cache_semantics.py
+++ b/tests/unittest/test_doclib_cache_semantics.py
@@ -645,7 +645,7 @@ def test_remap_api_result_pages_refreshes_attached_export_cache() -> None:
_remap_api_result_pages_to_page_range(result, "5")
- assert result.to_export_dict()["pages"][0]["page_idx"] == 4
+ assert result.to_dict()["pages"][0]["page_idx"] == 4
assert result.images() == {"images/figure.png": b"figure-bytes"}
diff --git a/tests/unittest/test_kit_commands.py b/tests/unittest/test_kit_commands.py
index e8f8e478..33309622 100644
--- a/tests/unittest/test_kit_commands.py
+++ b/tests/unittest/test_kit_commands.py
@@ -355,7 +355,7 @@ def test_parse_single_file_middle_json_writes_image_sidecars(
source.write_bytes(b"%PDF-1.7\n")
class _Result:
- def to_export_json(self) -> str:
+ def to_json(self) -> str:
"""返回带图片引用的 public middle_json。"""
return '{"pages":[{"para_blocks":[{"lines":[{"spans":[{"image_path":"figure.png"}]}]}]}]}'
@@ -388,7 +388,7 @@ def test_parse_single_file_middle_json_rejects_parent_sidecar_paths(
source.write_bytes(b"%PDF-1.7\n")
class _Result:
- def to_export_json(self) -> str:
+ def to_json(self) -> str:
"""返回引用逃逸路径的 public middle_json。"""
return '{"pages":[]}'
@@ -419,7 +419,7 @@ def test_parse_single_file_middle_json_rejects_absolute_sidecar_paths(
source.write_bytes(b"%PDF-1.7\n")
class _Result:
- def to_export_json(self) -> str:
+ def to_json(self) -> str:
"""返回普通 public middle_json 内容,重点验证 sidecar 路径。"""
return '{"pages":[]}'
@@ -449,7 +449,7 @@ def test_parse_single_file_middle_json_rejects_windows_rooted_sidecar_paths(
source.write_bytes(b"%PDF-1.7\n")
class _Result:
- def to_export_json(self) -> str:
+ def to_json(self) -> str:
"""返回普通 public middle_json 内容,重点验证 Windows 路径。"""
return '{"pages":[]}'
diff --git a/tests/unittest/test_parse_result_contract.py b/tests/unittest/test_parse_result_contract.py
index 28892848..01d55669 100644
--- a/tests/unittest/test_parse_result_contract.py
+++ b/tests/unittest/test_parse_result_contract.py
@@ -421,7 +421,7 @@ def test_parse_result_public_outputs_use_top_level_image_cache() -> None:
"markdown": result.markdown(),
"content_list": result.content_list(),
"structured_content": result.structured_content(),
- "middle_json": result.to_export_dict(),
+ "middle_json": result.to_dict(),
"images": sorted(result.images()),
},
ensure_ascii=False,
@@ -441,7 +441,7 @@ def test_parse_result_export_pages_returns_defensive_copy_from_cache() -> None:
second_export = result.export_pages()
second_content = second_export[0].para_blocks[0].lines[0].spans[0].content
- exported_json = json.dumps(result.to_export_dict(), ensure_ascii=False)
+ exported_json = json.dumps(result.to_dict(), ensure_ascii=False)
assert "mutated by caller" not in second_content
assert "mutated by caller" not in exported_json
@@ -458,7 +458,7 @@ def test_parse_result_export_rewrites_inline_table_base64_images() -> None:
images = result.images()
exported_page = result.export_pages()[0]
exported_span = exported_page.para_blocks[0].lines[0].spans[0]
- exported_json = json.dumps(result.to_export_dict(), ensure_ascii=False)
+ exported_json = json.dumps(result.to_dict(), ensure_ascii=False)
assert list(images.values()) == [img_bytes]
assert inline_image not in exported_json