Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docling_core/types/doc/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy
import hashlib
import json
import orjson
import logging
import mimetypes
import os
Expand Down Expand Up @@ -4860,7 +4861,10 @@ def save_as_json(
coord_precision: Optional[int] = None,
confid_precision: Optional[int] = None,
):
"""Save as json."""
"""
Save as json.
Indent can either be 2 or 0 (no indent).
"""
if isinstance(filename, str):
filename = Path(filename)
artifacts_dir, reference_path = self._get_output_paths(filename, artifacts_dir)
Expand All @@ -4875,8 +4879,8 @@ def save_as_json(
out = new_doc.export_to_dict(
coord_precision=coord_precision, confid_precision=confid_precision
)
with open(filename, "w", encoding="utf-8") as fw:
json.dump(out, fw, indent=indent)
with open(filename, "wb") as fw:
fw.write(orjson.dumps(out, option=orjson.OPT_INDENT_2 if indent else 0))

@classmethod
def load_from_json(cls, filename: Union[str, Path]) -> "DoclingDocument":
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies = [
'typing-extensions (>=4.12.2,<5.0.0)',
'typer (>=0.12.5,<0.20.0)',
'latex2mathml (>=3.77.0,<4.0.0)',
"orjson>=3.11.5",
]

[project.urls]
Expand Down
22 changes: 11 additions & 11 deletions test/data/doc/constructed_doc.embedded.json.gt
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
"orig": "item of leading list",
"text": "item of leading list",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/1",
Expand Down Expand Up @@ -507,7 +507,7 @@
"orig": "list item 1",
"text": "list item 1",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/7",
Expand All @@ -521,7 +521,7 @@
"orig": "list item 2",
"text": "list item 2",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/8",
Expand All @@ -539,7 +539,7 @@
"orig": "list item 3",
"text": "list item 3",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/9",
Expand Down Expand Up @@ -613,7 +613,7 @@
"orig": "list item 4",
"text": "list item 4",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/14",
Expand Down Expand Up @@ -663,7 +663,7 @@
"orig": "item 1 of list",
"text": "item 1 of list",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/18",
Expand Down Expand Up @@ -705,7 +705,7 @@
"orig": "item 1 of neighboring list",
"text": "item 1 of neighboring list",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/21",
Expand All @@ -723,7 +723,7 @@
"orig": "item 2 of neighboring list",
"text": "item 2 of neighboring list",
"enumerated": false,
"marker": "\u25a0"
"marker": ""
},
{
"self_ref": "#/texts/22",
Expand All @@ -737,7 +737,7 @@
"orig": "item 1 of sub list",
"text": "item 1 of sub list",
"enumerated": false,
"marker": "\u25a1"
"marker": ""
},
{
"self_ref": "#/texts/23",
Expand All @@ -755,7 +755,7 @@
"orig": "",
"text": "",
"enumerated": false,
"marker": "\u25a1"
"marker": ""
},
{
"self_ref": "#/texts/24",
Expand Down Expand Up @@ -813,7 +813,7 @@
"orig": "",
"text": "",
"enumerated": false,
"marker": "\u25a1"
"marker": ""
},
{
"self_ref": "#/texts/28",
Expand Down
Loading
Loading