json-repair 0.40.0__py3-none-any.whl → 0.41.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/json_parser.py +4 -0
- json_repair/object_comparer.py +63 -0
- {json_repair-0.40.0.dist-info → json_repair-0.41.0.dist-info}/METADATA +3 -2
- json_repair-0.41.0.dist-info/RECORD +14 -0
- {json_repair-0.40.0.dist-info → json_repair-0.41.0.dist-info}/WHEEL +1 -1
- json_repair-0.40.0.dist-info/RECORD +0 -13
- {json_repair-0.40.0.dist-info → json_repair-0.41.0.dist-info}/entry_points.txt +0 -0
- {json_repair-0.40.0.dist-info → json_repair-0.41.0.dist-info/licenses}/LICENSE +0 -0
- {json_repair-0.40.0.dist-info → json_repair-0.41.0.dist-info}/top_level.txt +0 -0
json_repair/json_parser.py
CHANGED
@@ -2,6 +2,7 @@ from typing import Any, Dict, List, Literal, Optional, TextIO, Tuple, Union
|
|
2
2
|
|
3
3
|
from .json_context import ContextValues, JsonContext
|
4
4
|
from .string_file_wrapper import StringFileWrapper
|
5
|
+
from .object_comparer import ObjectComparer
|
5
6
|
|
6
7
|
JSONReturnType = Union[Dict[str, Any], List[Any], str, float, int, bool, None]
|
7
8
|
|
@@ -54,6 +55,9 @@ class JSONParser:
|
|
54
55
|
while self.index < len(self.json_str):
|
55
56
|
j = self.parse_json()
|
56
57
|
if j != "":
|
58
|
+
if ObjectComparer.is_same_object(json[-1], j):
|
59
|
+
# replace the last entry with the new one since the new one seems an update
|
60
|
+
json.pop()
|
57
61
|
json.append(j)
|
58
62
|
if self.index == last_index:
|
59
63
|
self.index += 1
|
@@ -0,0 +1,63 @@
|
|
1
|
+
from typing import Any
|
2
|
+
|
3
|
+
|
4
|
+
class ObjectComparer:
|
5
|
+
def __init__(self) -> None:
|
6
|
+
return
|
7
|
+
|
8
|
+
@staticmethod
|
9
|
+
def is_same_object(obj1: Any, obj2: Any, path: str = "") -> bool:
|
10
|
+
"""
|
11
|
+
Recursively compares two objects and ensures that:
|
12
|
+
- Their types match
|
13
|
+
- Their keys/structure match
|
14
|
+
"""
|
15
|
+
if type(obj1) is not type(obj2):
|
16
|
+
# Fail immediately if the types don't match
|
17
|
+
print(
|
18
|
+
f"Type mismatch at {path}: {type(obj1).__name__} vs {type(obj2).__name__}"
|
19
|
+
)
|
20
|
+
return False
|
21
|
+
|
22
|
+
if isinstance(obj1, dict) and isinstance(obj2, dict):
|
23
|
+
# Compare dictionary keys
|
24
|
+
keys1, keys2 = set(obj1.keys()), set(obj2.keys())
|
25
|
+
common_keys = keys1 & keys2
|
26
|
+
extra_keys1 = keys1 - keys2
|
27
|
+
extra_keys2 = keys2 - keys1
|
28
|
+
|
29
|
+
if extra_keys1:
|
30
|
+
print(f"Extra keys in first object at {path}: {extra_keys1}")
|
31
|
+
return False
|
32
|
+
if extra_keys2:
|
33
|
+
print(f"Extra keys in second object at {path}: {extra_keys2}")
|
34
|
+
return False
|
35
|
+
|
36
|
+
# Recursively compare the common keys
|
37
|
+
for key in common_keys:
|
38
|
+
if not ObjectComparer.is_same_object(
|
39
|
+
obj1[key], obj2[key], path=f"{path}/{key}"
|
40
|
+
):
|
41
|
+
return False
|
42
|
+
|
43
|
+
elif isinstance(obj1, list) and isinstance(obj2, list):
|
44
|
+
# Compare lists
|
45
|
+
min_length = min(len(obj1), len(obj2))
|
46
|
+
if len(obj1) != len(obj2):
|
47
|
+
print(f"Length mismatch at {path}: {len(obj1)} vs {len(obj2)}")
|
48
|
+
return False
|
49
|
+
|
50
|
+
for i in range(min_length):
|
51
|
+
if not ObjectComparer.is_same_object(
|
52
|
+
obj1[i], obj2[i], path=f"{path}[{i}]"
|
53
|
+
):
|
54
|
+
return False
|
55
|
+
|
56
|
+
if len(obj1) > len(obj2):
|
57
|
+
print(f"Extra items in first list at {path}: {obj1[min_length:]}")
|
58
|
+
return False
|
59
|
+
elif len(obj2) > len(obj1):
|
60
|
+
print(f"Extra items in second list at {path}: {obj2[min_length:]}")
|
61
|
+
return False
|
62
|
+
|
63
|
+
return True
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.41.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
|
@@ -35,6 +35,7 @@ Classifier: Operating System :: OS Independent
|
|
35
35
|
Requires-Python: >=3.9
|
36
36
|
Description-Content-Type: text/markdown
|
37
37
|
License-File: LICENSE
|
38
|
+
Dynamic: license-file
|
38
39
|
|
39
40
|
[](https://pypi.org/project/json-repair/)
|
40
41
|

|
@@ -0,0 +1,14 @@
|
|
1
|
+
json_repair/__init__.py,sha256=c4L2kZrHvWEKfj_ODU2naliNuvU6FlFVxtF0hbLe6s8,178
|
2
|
+
json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
|
3
|
+
json_repair/json_context.py,sha256=mm6dOyrPJ1sDskTORZSXCW7W9-5veMlUKqXQ3Hw3EG4,971
|
4
|
+
json_repair/json_parser.py,sha256=ff5LPEHVfaRJ7ujVxUm7dxiwlHPzcJK0cGItm_OilpU,38996
|
5
|
+
json_repair/json_repair.py,sha256=k-5HRRlCqrxNmJi0u1KE3IUeL4HXqi1XZ7oAL-NFDLo,10314
|
6
|
+
json_repair/object_comparer.py,sha256=oMWtBySgrHDH8q2v72HnNQm8SRmudtEsVPkaydSXckE,2210
|
7
|
+
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
+
json_repair/string_file_wrapper.py,sha256=koZmdq2-Z5K7XF1bDqX6dEbNaVMJYcMTjq-aGe6NQvA,4526
|
9
|
+
json_repair-0.41.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
10
|
+
json_repair-0.41.0.dist-info/METADATA,sha256=9cD1PLAiAi5giNrDwS0TVerOD-wuzEd6wKrE1OeF-Jw,11860
|
11
|
+
json_repair-0.41.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
12
|
+
json_repair-0.41.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
13
|
+
json_repair-0.41.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
14
|
+
json_repair-0.41.0.dist-info/RECORD,,
|
@@ -1,13 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=c4L2kZrHvWEKfj_ODU2naliNuvU6FlFVxtF0hbLe6s8,178
|
2
|
-
json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
|
3
|
-
json_repair/json_context.py,sha256=mm6dOyrPJ1sDskTORZSXCW7W9-5veMlUKqXQ3Hw3EG4,971
|
4
|
-
json_repair/json_parser.py,sha256=aw-iCtblc9iL24w5zljHbbblK7Ao6G49MPoj513D2KE,38750
|
5
|
-
json_repair/json_repair.py,sha256=k-5HRRlCqrxNmJi0u1KE3IUeL4HXqi1XZ7oAL-NFDLo,10314
|
6
|
-
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
json_repair/string_file_wrapper.py,sha256=koZmdq2-Z5K7XF1bDqX6dEbNaVMJYcMTjq-aGe6NQvA,4526
|
8
|
-
json_repair-0.40.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
9
|
-
json_repair-0.40.0.dist-info/METADATA,sha256=i43pAASjiIvd0XJ3CMO1nqaV14JNE2MjPx0U8lMJVYc,11838
|
10
|
-
json_repair-0.40.0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
11
|
-
json_repair-0.40.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
12
|
-
json_repair-0.40.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
13
|
-
json_repair-0.40.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|