Save SegmentedPdfPage as JSON with floats rounded to ndigits.
(page: SegmentedPdfPage, filename, indent=2, ndigits=3)
| 48 | |
| 49 | |
| 50 | def 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 | |
| 62 | GROUNDTRUTH_FOLDER = os.fspath(PARSER_GROUNDTRUTH_DIR) |
no test coverage detected