json-repair 0.41.0__tar.gz → 0.42.0__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.41.0/src/json_repair.egg-info → json_repair-0.42.0}/PKG-INFO +1 -1
- {json_repair-0.41.0 → json_repair-0.42.0}/pyproject.toml +13 -1
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/json_parser.py +7 -3
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/object_comparer.py +0 -8
- {json_repair-0.41.0 → json_repair-0.42.0/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.41.0 → json_repair-0.42.0}/tests/test_json_repair.py +5 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/LICENSE +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/README.md +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/setup.cfg +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/__init__.py +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/__main__.py +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/json_context.py +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/py.typed +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/tests/test_coverage.py +0 -0
- {json_repair-0.41.0 → json_repair-0.42.0}/tests/test_performance.py +0 -0
@@ -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.42.0"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -31,3 +31,15 @@ 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"]
|
43
|
+
[tool.ruff.lint.per-file-ignores]
|
44
|
+
# Explicit re-exports is fine in __init__.py, still a code smell elsewhere.
|
45
|
+
"__init__.py" = ["PLC0414"]
|
@@ -1,8 +1,8 @@
|
|
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 .string_file_wrapper import StringFileWrapper
|
5
4
|
from .object_comparer import ObjectComparer
|
5
|
+
from .string_file_wrapper import StringFileWrapper
|
6
6
|
|
7
7
|
JSONReturnType = Union[Dict[str, Any], List[Any], str, float, int, bool, None]
|
8
8
|
|
@@ -10,7 +10,6 @@ JSONReturnType = Union[Dict[str, Any], List[Any], str, float, int, bool, None]
|
|
10
10
|
class JSONParser:
|
11
11
|
# Constants
|
12
12
|
STRING_DELIMITERS = ['"', "'", "“", "”"]
|
13
|
-
NUMBER_CHARS = set("0123456789-.eE/,")
|
14
13
|
|
15
14
|
def __init__(
|
16
15
|
self,
|
@@ -663,7 +662,8 @@ class JSONParser:
|
|
663
662
|
number_str = ""
|
664
663
|
char = self.get_char_at()
|
665
664
|
is_array = self.context.current == ContextValues.ARRAY
|
666
|
-
|
665
|
+
NUMBER_CHARS = set("0123456789-.eE/,")
|
666
|
+
while char and char in NUMBER_CHARS and (not is_array or char != ","):
|
667
667
|
number_str += char
|
668
668
|
self.index += 1
|
669
669
|
char = self.get_char_at()
|
@@ -671,6 +671,10 @@ class JSONParser:
|
|
671
671
|
# The number ends with a non valid character for a number/currency, rolling back one
|
672
672
|
number_str = number_str[:-1]
|
673
673
|
self.index -= 1
|
674
|
+
elif (self.get_char_at() or "").isalpha():
|
675
|
+
# this was a string instead, sorry
|
676
|
+
self.index -= len(number_str)
|
677
|
+
return self.parse_string()
|
674
678
|
try:
|
675
679
|
if "," in number_str:
|
676
680
|
return str(number_str)
|
@@ -14,9 +14,6 @@ class ObjectComparer:
|
|
14
14
|
"""
|
15
15
|
if type(obj1) is not type(obj2):
|
16
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
17
|
return False
|
21
18
|
|
22
19
|
if isinstance(obj1, dict) and isinstance(obj2, dict):
|
@@ -27,10 +24,8 @@ class ObjectComparer:
|
|
27
24
|
extra_keys2 = keys2 - keys1
|
28
25
|
|
29
26
|
if extra_keys1:
|
30
|
-
print(f"Extra keys in first object at {path}: {extra_keys1}")
|
31
27
|
return False
|
32
28
|
if extra_keys2:
|
33
|
-
print(f"Extra keys in second object at {path}: {extra_keys2}")
|
34
29
|
return False
|
35
30
|
|
36
31
|
# Recursively compare the common keys
|
@@ -44,7 +39,6 @@ class ObjectComparer:
|
|
44
39
|
# Compare lists
|
45
40
|
min_length = min(len(obj1), len(obj2))
|
46
41
|
if len(obj1) != len(obj2):
|
47
|
-
print(f"Length mismatch at {path}: {len(obj1)} vs {len(obj2)}")
|
48
42
|
return False
|
49
43
|
|
50
44
|
for i in range(min_length):
|
@@ -54,10 +48,8 @@ class ObjectComparer:
|
|
54
48
|
return False
|
55
49
|
|
56
50
|
if len(obj1) > len(obj2):
|
57
|
-
print(f"Extra items in first list at {path}: {obj1[min_length:]}")
|
58
51
|
return False
|
59
52
|
elif len(obj2) > len(obj1):
|
60
|
-
print(f"Extra items in second list at {path}: {obj2[min_length:]}")
|
61
53
|
return False
|
62
54
|
|
63
55
|
return True
|
@@ -179,6 +179,11 @@ def test_number_edge_cases():
|
|
179
179
|
assert repair_json('{"key": 10-20}') == '{"key": "10-20"}'
|
180
180
|
assert repair_json('{"key": 1.1.1}') == '{"key": "1.1.1"}'
|
181
181
|
assert repair_json('[- ') == '[]'
|
182
|
+
assert repair_json('{"key": 1. }') == '{"key": 1.0}'
|
183
|
+
assert repair_json('{"key": 1e10 }') == '{"key": 10000000000.0}'
|
184
|
+
assert repair_json('{"key": 1e }') == '{"key": 1}'
|
185
|
+
assert repair_json('{"key": 1notanumber }') == '{"key": "1notanumber"}'
|
186
|
+
assert repair_json('[1, 2notanumber]') == '[1, "2notanumber"]'
|
182
187
|
|
183
188
|
def test_markdown():
|
184
189
|
assert repair_json('{ "content": "[LINK]("https://google.com")" }') == '{"content": "[LINK](\\"https://google.com\\")"}'
|
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
|
File without changes
|