json-repair 0.12.3__py3-none-any.whl → 0.13.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- json_repair/__init__.py +2 -0
- json_repair/json_repair.py +15 -1
- {json_repair-0.12.3.dist-info → json_repair-0.13.0.dist-info}/METADATA +28 -1
- json_repair-0.13.0.dist-info/RECORD +7 -0
- json_repair-0.12.3.dist-info/RECORD +0 -7
- {json_repair-0.12.3.dist-info → json_repair-0.13.0.dist-info}/LICENSE +0 -0
- {json_repair-0.12.3.dist-info → json_repair-0.13.0.dist-info}/WHEEL +0 -0
- {json_repair-0.12.3.dist-info → json_repair-0.13.0.dist-info}/top_level.txt +0 -0
json_repair/__init__.py
CHANGED
json_repair/json_repair.py
CHANGED
@@ -23,7 +23,7 @@ All supported use cases are in the unit tests
|
|
23
23
|
"""
|
24
24
|
|
25
25
|
import json
|
26
|
-
from typing import Any, Dict, List, Union
|
26
|
+
from typing import Any, Dict, List, Union, TextIO
|
27
27
|
|
28
28
|
|
29
29
|
class JSONParser:
|
@@ -351,3 +351,17 @@ def loads(
|
|
351
351
|
It is a wrapper around the `repair_json()` function with `return_objects=True`.
|
352
352
|
"""
|
353
353
|
return repair_json(json_str, True)
|
354
|
+
|
355
|
+
|
356
|
+
def load(fp: TextIO) -> Union[Dict[str, Any], List[Any], str, float, int, bool, None]:
|
357
|
+
return loads(fp.read())
|
358
|
+
|
359
|
+
|
360
|
+
def from_file(
|
361
|
+
filename: str,
|
362
|
+
) -> Union[Dict[str, Any], List[Any], str, float, int, bool, None]:
|
363
|
+
fd = open(filename)
|
364
|
+
jsonobj = load(fd)
|
365
|
+
fd.close()
|
366
|
+
|
367
|
+
return jsonobj
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.13.0
|
4
4
|
Summary: A package to repair broken json strings
|
5
5
|
Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
|
6
6
|
License: MIT License
|
@@ -65,6 +65,33 @@ or just
|
|
65
65
|
|
66
66
|
decoded_object = json_repair.repair_json(json_string, return_objects=True)
|
67
67
|
|
68
|
+
### Read json from a file or file descriptor
|
69
|
+
|
70
|
+
JSON repair provides also a drop-in replacement for `json.load()`:
|
71
|
+
|
72
|
+
import json_repair
|
73
|
+
|
74
|
+
try:
|
75
|
+
file_descriptor = open(fname, 'rb')
|
76
|
+
except OSError:
|
77
|
+
...
|
78
|
+
|
79
|
+
with file_descriptor:
|
80
|
+
decoded_object = json_repair.load(file_descriptor)
|
81
|
+
|
82
|
+
and another method to read from a file:
|
83
|
+
|
84
|
+
import json_repair
|
85
|
+
|
86
|
+
try:
|
87
|
+
decoded_object = json_repair.from_file(json_file)
|
88
|
+
except OSError:
|
89
|
+
...
|
90
|
+
except IOError:
|
91
|
+
...
|
92
|
+
|
93
|
+
Keep in mind that the library will not catch any IO-related exception and those will need to be managed by you
|
94
|
+
|
68
95
|
### Performance considerations
|
69
96
|
If you find this library too slow because is using `json.loads()` you can skip that by passing `skip_json_loads=True` to `repair_json`. Like:
|
70
97
|
|
@@ -0,0 +1,7 @@
|
|
1
|
+
json_repair/__init__.py,sha256=AlNie5y6BZBioGi5fzTAUvum_y0U5aL5aNsuQ_68LQc,175
|
2
|
+
json_repair/json_repair.py,sha256=BHDcvo8C-vc3QO4dhgD5cP7IZVkGWGDbv8hNmQH1B-I,14653
|
3
|
+
json_repair-0.13.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
+
json_repair-0.13.0.dist-info/METADATA,sha256=E6v_JcBwXe4oMJhtxgF-9-24kG2j5LiH-ivqufNHFpA,7200
|
5
|
+
json_repair-0.13.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
json_repair-0.13.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
+
json_repair-0.13.0.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=p9mZnte8Bg18NcxqgJ7vopH2gQv_XbZ0dRnk686QuRE,92
|
2
|
-
json_repair/json_repair.py,sha256=363JdAjrrpgVWvt5FOLoSHRPaq1oQoLsYsiX3yf7Z1k,14342
|
3
|
-
json_repair-0.12.3.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
-
json_repair-0.12.3.dist-info/METADATA,sha256=_ZJNBrJWIGOPlyxJ0kOAPGIry2XBn6FLqWrxG93ijmA,6581
|
5
|
-
json_repair-0.12.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
json_repair-0.12.3.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
-
json_repair-0.12.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|