Download structured_json.py from ATH-MaaS/OvisOCR3: direct link, hf CLI and curl.
- Browser
- Download file 695 Bytes
-
https://huggingface.co/spaces/ATH-MaaS/OvisOCR3/resolve/main/structured_json.py
- Command line
-
hf download hf://spaces/ATH-MaaS/OvisOCR3/structured_json.py
-
curl -L -o structured_json.py https://huggingface.co/spaces/ATH-MaaS/OvisOCR3/resolve/main/structured_json.py
695 Bytes
| """Strict JSON decoding without silent key loss or non-JSON numeric values.""" | |
| import json | |
| import math | |
| def _object(pairs): | |
| result = {} | |
| for key, value in pairs: | |
| if key in result: | |
| raise ValueError(f"Duplicate JSON key: {key!r}.") | |
| result[key] = value | |
| return result | |
| def _constant(value): | |
| raise ValueError(f"{value} is not a valid JSON value.") | |
| def _float(value): | |
| number = float(value) | |
| if not math.isfinite(number): | |
| raise ValueError("JSON number exceeds the supported finite range.") | |
| return number | |
| def strict_json_loads(text): | |
| return json.loads(text, object_pairs_hook=_object, parse_constant=_constant, parse_float=_float) | |