json-repair 0.40.0__tar.gz → 0.41.1__tar.gz
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-0.40.0/src/json_repair.egg-info → json_repair-0.41.1}/PKG-INFO +3 -2
- {json_repair-0.40.0 → json_repair-0.41.1}/pyproject.toml +10 -1
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair/json_parser.py +4 -0
- json_repair-0.41.1/src/json_repair/object_comparer.py +55 -0
- {json_repair-0.40.0 → json_repair-0.41.1/src/json_repair.egg-info}/PKG-INFO +3 -2
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair.egg-info/SOURCES.txt +1 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/tests/test_json_repair.py +1 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/LICENSE +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/README.md +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/setup.cfg +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair/__init__.py +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair/__main__.py +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair/json_context.py +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair/py.typed +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/tests/test_coverage.py +0 -0
- {json_repair-0.40.0 → json_repair-0.41.1}/tests/test_performance.py +0 -0
@@ -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.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
|
[](https://pypi.org/project/json-repair/)
|
40
41
|

|
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
4
4
|
[project]
|
5
5
|
name = "json_repair"
|
6
|
-
version = "0.
|
6
|
+
version = "0.41.1"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -31,3 +31,12 @@ pythonpath = [
|
|
31
31
|
where = ["src"]
|
32
32
|
[project.scripts]
|
33
33
|
json_repair = "json_repair.__main__:cli"
|
34
|
+
[tool.ruff.lint]
|
35
|
+
# Read more here https://docs.astral.sh/ruff/rules/
|
36
|
+
# By default, Ruff enables Flake8's E and F rules
|
37
|
+
# Pyflakes - F, pycodestyle - E, W
|
38
|
+
# flake8-builtins - A
|
39
|
+
# Pylint - PLC, PLE, PLW
|
40
|
+
# isort - I
|
41
|
+
select = ['E', 'F', 'W', 'A', 'PLC', 'PLE', 'PLW', 'I']
|
42
|
+
ignore = ["E501"]
|
@@ -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.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: json_repair
|
3
|
-
Version: 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
|
[](https://pypi.org/project/json-repair/)
|
40
41
|

|
@@ -6,6 +6,7 @@ src/json_repair/__main__.py
|
|
6
6
|
src/json_repair/json_context.py
|
7
7
|
src/json_repair/json_parser.py
|
8
8
|
src/json_repair/json_repair.py
|
9
|
+
src/json_repair/object_comparer.py
|
9
10
|
src/json_repair/py.typed
|
10
11
|
src/json_repair/string_file_wrapper.py
|
11
12
|
src/json_repair.egg-info/PKG-INFO
|
@@ -199,6 +199,7 @@ def test_multiple_jsons():
|
|
199
199
|
assert repair_json("{}[]{}") == "[{}, [], {}]"
|
200
200
|
assert repair_json('{"key":"value"}[1,2,3,True]') == '[{"key": "value"}, [1, 2, 3, true]]'
|
201
201
|
assert repair_json('lorem ```json {"key":"value"} ``` ipsum ```json [1,2,3,True] ``` 42') == '[{"key": "value"}, [1, 2, 3, true]]'
|
202
|
+
assert repair_json('[{"key":"value"}][{"key":"value_after"}]') == '[{"key": "value_after"}]'
|
202
203
|
|
203
204
|
def test_repair_json_with_objects():
|
204
205
|
# Test with valid JSON strings
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|