json-repair 0.40.0__py3-none-any.whl → 0.41.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.
@@ -1,6 +1,7 @@
1
1
  from typing import Any, Dict, List, Literal, Optional, TextIO, Tuple, Union
2
2
 
3
3
  from .json_context import ContextValues, JsonContext
4
+ from .object_comparer import ObjectComparer
4
5
  from .string_file_wrapper import StringFileWrapper
5
6
 
6
7
  JSONReturnType = Union[Dict[str, Any], List[Any], str, float, int, bool, None]
@@ -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,55 @@
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
+ return False
18
+
19
+ if isinstance(obj1, dict) and isinstance(obj2, dict):
20
+ # Compare dictionary keys
21
+ keys1, keys2 = set(obj1.keys()), set(obj2.keys())
22
+ common_keys = keys1 & keys2
23
+ extra_keys1 = keys1 - keys2
24
+ extra_keys2 = keys2 - keys1
25
+
26
+ if extra_keys1:
27
+ return False
28
+ if extra_keys2:
29
+ return False
30
+
31
+ # Recursively compare the common keys
32
+ for key in common_keys:
33
+ if not ObjectComparer.is_same_object(
34
+ obj1[key], obj2[key], path=f"{path}/{key}"
35
+ ):
36
+ return False
37
+
38
+ elif isinstance(obj1, list) and isinstance(obj2, list):
39
+ # Compare lists
40
+ min_length = min(len(obj1), len(obj2))
41
+ if len(obj1) != len(obj2):
42
+ return False
43
+
44
+ for i in range(min_length):
45
+ if not ObjectComparer.is_same_object(
46
+ obj1[i], obj2[i], path=f"{path}[{i}]"
47
+ ):
48
+ return False
49
+
50
+ if len(obj1) > len(obj2):
51
+ return False
52
+ elif len(obj2) > len(obj1):
53
+ return False
54
+
55
+ return True
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.40.0
3
+ Version: 0.41.1
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
  [![PyPI](https://img.shields.io/pypi/v/json-repair)](https://pypi.org/project/json-repair/)
40
41
  ![Python version](https://img.shields.io/badge/python-3.9+-important)
@@ -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=VnTlhPEuIynUt3gaAU2jpLJDddnPASxM941rYyMnGbo,38996
5
+ json_repair/json_repair.py,sha256=k-5HRRlCqrxNmJi0u1KE3IUeL4HXqi1XZ7oAL-NFDLo,10314
6
+ json_repair/object_comparer.py,sha256=SeicB6_N4BHAEPon7s2BELEaJc4oyR9ZhfX2RgPk6Bw,1682
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.1.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
10
+ json_repair-0.41.1.dist-info/METADATA,sha256=HnZgNiwsJJ3iwtFKgeccdm-yniRJnPq70kjcpQo6aw0,11860
11
+ json_repair-0.41.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
12
+ json_repair-0.41.1.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
13
+ json_repair-0.41.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
14
+ json_repair-0.41.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.1.0)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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,,