json-repair 0.44.0__py3-none-any.whl → 0.44.1__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/json_parser.py +3 -3
- json_repair/json_repair.py +30 -4
- {json_repair-0.44.0.dist-info → json_repair-0.44.1.dist-info}/METADATA +1 -1
- {json_repair-0.44.0.dist-info → json_repair-0.44.1.dist-info}/RECORD +8 -8
- {json_repair-0.44.0.dist-info → json_repair-0.44.1.dist-info}/WHEEL +1 -1
- {json_repair-0.44.0.dist-info → json_repair-0.44.1.dist-info}/entry_points.txt +0 -0
- {json_repair-0.44.0.dist-info → json_repair-0.44.1.dist-info}/licenses/LICENSE +0 -0
- {json_repair-0.44.0.dist-info → json_repair-0.44.1.dist-info}/top_level.txt +0 -0
json_repair/json_parser.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any, Dict, List, Literal, Optional, TextIO, Tuple, Union
|
1
|
+
from typing import Any, ClassVar, Dict, List, Literal, Optional, TextIO, Tuple, Union
|
2
2
|
|
3
3
|
from .json_context import ContextValues, JsonContext
|
4
4
|
from .object_comparer import ObjectComparer
|
@@ -9,7 +9,7 @@ JSONReturnType = Union[Dict[str, Any], List[Any], str, float, int, bool, None]
|
|
9
9
|
|
10
10
|
class JSONParser:
|
11
11
|
# Constants
|
12
|
-
STRING_DELIMITERS = ['"', "'", "“", "”"]
|
12
|
+
STRING_DELIMITERS: ClassVar[list[str]] = ['"', "'", "“", "”"]
|
13
13
|
|
14
14
|
def __init__(
|
15
15
|
self,
|
@@ -343,7 +343,7 @@ class JSONParser:
|
|
343
343
|
# Ok this is not a doubled quote, check if this is an empty string or not
|
344
344
|
i = self.skip_whitespaces_at(idx=1, move_main_index=False)
|
345
345
|
next_c = self.get_char_at(i)
|
346
|
-
if next_c in self.STRING_DELIMITERS
|
346
|
+
if next_c in [*self.STRING_DELIMITERS, "{", "["]:
|
347
347
|
# something fishy is going on here
|
348
348
|
self.log(
|
349
349
|
"While parsing a string, we found a doubled quote but also another quote afterwards, ignoring it",
|
json_repair/json_repair.py
CHANGED
@@ -25,11 +25,37 @@ All supported use cases are in the unit tests
|
|
25
25
|
import argparse
|
26
26
|
import json
|
27
27
|
import sys
|
28
|
-
from typing import Dict, List, Optional, TextIO, Tuple, Union
|
28
|
+
from typing import Dict, List, Literal, Optional, TextIO, Tuple, Union, overload
|
29
29
|
|
30
30
|
from .json_parser import JSONParser, JSONReturnType
|
31
31
|
|
32
32
|
|
33
|
+
@overload
|
34
|
+
def repair_json(
|
35
|
+
json_str: str = "",
|
36
|
+
return_objects: Literal[False] = False,
|
37
|
+
skip_json_loads: bool = False,
|
38
|
+
logging: bool = False,
|
39
|
+
json_fd: Optional[TextIO] = None,
|
40
|
+
ensure_ascii: bool = True,
|
41
|
+
chunk_length: int = 0,
|
42
|
+
stream_stable: bool = False,
|
43
|
+
) -> str: ...
|
44
|
+
|
45
|
+
|
46
|
+
@overload
|
47
|
+
def repair_json(
|
48
|
+
json_str: str = "",
|
49
|
+
return_objects: Literal[True] = True,
|
50
|
+
skip_json_loads: bool = False,
|
51
|
+
logging: bool = False,
|
52
|
+
json_fd: Optional[TextIO] = None,
|
53
|
+
ensure_ascii: bool = True,
|
54
|
+
chunk_length: int = 0,
|
55
|
+
stream_stable: bool = False,
|
56
|
+
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]: ...
|
57
|
+
|
58
|
+
|
33
59
|
def repair_json(
|
34
60
|
json_str: str = "",
|
35
61
|
return_objects: bool = False,
|
@@ -78,7 +104,7 @@ def loads(
|
|
78
104
|
skip_json_loads: bool = False,
|
79
105
|
logging: bool = False,
|
80
106
|
stream_stable: bool = False,
|
81
|
-
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]:
|
107
|
+
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]], str]:
|
82
108
|
"""
|
83
109
|
This function works like `json.loads()` except that it will fix your JSON in the process.
|
84
110
|
It is a wrapper around the `repair_json()` function with `return_objects=True`.
|
@@ -89,7 +115,7 @@ def loads(
|
|
89
115
|
logging (bool, optional): If True, return a tuple with the repaired json and a log of all repair actions. Defaults to False.
|
90
116
|
|
91
117
|
Returns:
|
92
|
-
Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]: The repaired JSON object or a tuple with the repaired JSON object and repair log.
|
118
|
+
Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]], str]: The repaired JSON object or a tuple with the repaired JSON object and repair log.
|
93
119
|
"""
|
94
120
|
return repair_json(
|
95
121
|
json_str=json_str,
|
@@ -241,7 +267,7 @@ def cli(inline_args: Optional[List[str]] = None) -> int:
|
|
241
267
|
else:
|
242
268
|
print(json.dumps(result, indent=args.indent, ensure_ascii=ensure_ascii))
|
243
269
|
except Exception as e: # pragma: no cover
|
244
|
-
print(f"Error: {
|
270
|
+
print(f"Error: {e!s}", file=sys.stderr)
|
245
271
|
return 1
|
246
272
|
|
247
273
|
return 0 # Success
|
@@ -1,14 +1,14 @@
|
|
1
1
|
json_repair/__init__.py,sha256=c4L2kZrHvWEKfj_ODU2naliNuvU6FlFVxtF0hbLe6s8,178
|
2
2
|
json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
|
3
3
|
json_repair/json_context.py,sha256=mm6dOyrPJ1sDskTORZSXCW7W9-5veMlUKqXQ3Hw3EG4,971
|
4
|
-
json_repair/json_parser.py,sha256=
|
5
|
-
json_repair/json_repair.py,sha256=
|
4
|
+
json_repair/json_parser.py,sha256=wmDgXAroQ4gYZdi4Tbdn3LKXnx2x2v_uanzSzqP0aSQ,42003
|
5
|
+
json_repair/json_repair.py,sha256=r-Mtr16U_n2wmHX_zNRZI2ZlLc0AV0fLWlLzGEWjJa0,11312
|
6
6
|
json_repair/object_comparer.py,sha256=SeicB6_N4BHAEPon7s2BELEaJc4oyR9ZhfX2RgPk6Bw,1682
|
7
7
|
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
json_repair/string_file_wrapper.py,sha256=koZmdq2-Z5K7XF1bDqX6dEbNaVMJYcMTjq-aGe6NQvA,4526
|
9
|
-
json_repair-0.44.
|
10
|
-
json_repair-0.44.
|
11
|
-
json_repair-0.44.
|
12
|
-
json_repair-0.44.
|
13
|
-
json_repair-0.44.
|
14
|
-
json_repair-0.44.
|
9
|
+
json_repair-0.44.1.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
10
|
+
json_repair-0.44.1.dist-info/METADATA,sha256=VJv39wNseOemAA5tQe1dIW4ZPXFoLXFTPBCGLlLRwN8,12157
|
11
|
+
json_repair-0.44.1.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
|
12
|
+
json_repair-0.44.1.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
13
|
+
json_repair-0.44.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
14
|
+
json_repair-0.44.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|