MCPcopy Create free account
hub / github.com/docling-project/docling-parse / save_as_json_rounded

Function save_as_json_rounded

tests/test_parse.py:50–59  ·  view source on GitHub ↗

Save SegmentedPdfPage as JSON with floats rounded to ndigits.

(page: SegmentedPdfPage, filename, indent=2, ndigits=3)

Source from the content-addressed store, hash-verified

48
49
50def save_as_json_rounded(page: SegmentedPdfPage, filename, indent=2, ndigits=3):
51 """Save SegmentedPdfPage as JSON with floats rounded to ndigits."""
52 from pathlib import Path
53
54 if isinstance(filename, str):
55 filename = Path(filename)
56 filename.parent.mkdir(parents=True, exist_ok=True)
57 out = _round_floats(page.export_to_dict(), ndigits=ndigits)
58 with open(filename, "w", encoding="utf-8") as fw:
59 json.dump(out, fw, indent=indent)
60
61
62GROUNDTRUTH_FOLDER = os.fspath(PARSER_GROUNDTRUTH_DIR)

Calls 1

_round_floatsFunction · 0.85

Tested by

no test coverage detected