json-repair 0.21.0__tar.gz → 0.22.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.21.0/src/json_repair.egg-info → json_repair-0.22.0}/PKG-INFO +1 -1
- {json_repair-0.21.0 → json_repair-0.22.0}/pyproject.toml +1 -1
- {json_repair-0.21.0 → json_repair-0.22.0}/src/json_repair/json_repair.py +5 -3
- {json_repair-0.21.0 → json_repair-0.22.0/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.21.0 → json_repair-0.22.0}/tests/test_json_repair.py +5 -4
- {json_repair-0.21.0 → json_repair-0.22.0}/tests/test_performance.py +3 -3
- {json_repair-0.21.0 → json_repair-0.22.0}/LICENSE +0 -0
- {json_repair-0.21.0 → json_repair-0.22.0}/README.md +0 -0
- {json_repair-0.21.0 → json_repair-0.22.0}/setup.cfg +0 -0
- {json_repair-0.21.0 → json_repair-0.22.0}/src/json_repair/__init__.py +0 -0
- {json_repair-0.21.0 → json_repair-0.22.0}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.21.0 → json_repair-0.22.0}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.21.0 → json_repair-0.22.0}/src/json_repair.egg-info/top_level.txt +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.22.0"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"""
|
2
2
|
This module will parse the JSON file following the BNF definition:
|
3
3
|
|
4
|
-
<json> ::= <
|
4
|
+
<json> ::= <container>
|
5
5
|
|
6
6
|
<primitive> ::= <number> | <string> | <boolean>
|
7
7
|
; Where:
|
@@ -98,6 +98,8 @@ class JSONParser:
|
|
98
98
|
self,
|
99
99
|
) -> JSONReturnType:
|
100
100
|
char = self.get_char_at()
|
101
|
+
# This parser will ignore any basic element (string or number) that is not inside an array or object
|
102
|
+
is_in_context = len(self.context) > 0
|
101
103
|
# False means that we are at the end of the string provided, is the base case for recursion
|
102
104
|
if char is False:
|
103
105
|
return ""
|
@@ -120,10 +122,10 @@ class JSONParser:
|
|
120
122
|
)
|
121
123
|
return ""
|
122
124
|
# <string> starts with a quote
|
123
|
-
elif char in ['"', "'", "“"] or char.isalpha():
|
125
|
+
elif is_in_context and (char in ['"', "'", "“"] or char.isalpha()):
|
124
126
|
return self.parse_string()
|
125
127
|
# <number> starts with [0-9] or minus
|
126
|
-
elif char.isdigit() or char == "-" or char == ".":
|
128
|
+
elif is_in_context and (char.isdigit() or char == "-" or char == "."):
|
127
129
|
return self.parse_number()
|
128
130
|
# If everything else fails, we just ignore and move on
|
129
131
|
else:
|
@@ -1,9 +1,9 @@
|
|
1
1
|
from src.json_repair.json_repair import from_file, repair_json, loads
|
2
2
|
|
3
3
|
def test_basic_types_valid():
|
4
|
-
assert repair_json("True", return_objects=True) ==
|
5
|
-
assert repair_json("False", return_objects=True) ==
|
6
|
-
assert repair_json("Null", return_objects=True) ==
|
4
|
+
assert repair_json("True", return_objects=True) == ""
|
5
|
+
assert repair_json("False", return_objects=True) == ""
|
6
|
+
assert repair_json("Null", return_objects=True) == ""
|
7
7
|
assert repair_json("1", return_objects=True) == 1
|
8
8
|
assert repair_json("[]", return_objects=True) == []
|
9
9
|
assert repair_json("[1, 2, 3, 4]", return_objects=True) == [1, 2, 3, 4]
|
@@ -114,7 +114,7 @@ def test_array_edge_cases():
|
|
114
114
|
|
115
115
|
|
116
116
|
def test_escaping():
|
117
|
-
assert repair_json("'\"'") == '"
|
117
|
+
assert repair_json("'\"'") == '""'
|
118
118
|
assert repair_json("{\"key\": 'string\"\n\t\le'") == '{"key": "string\\"\\n\\tle"}'
|
119
119
|
assert repair_json(r'{"real_content": "Some string: Some other string \t Some string <a href=\"https://domain.com\">Some link</a>"') == r'{"real_content": "Some string: Some other string \t Some string <a href=\"https://domain.com\">Some link</a>"}'
|
120
120
|
assert repair_json('{"key_1\n": "value"}') == '{"key_1": "value"}'
|
@@ -164,6 +164,7 @@ def test_leading_trailing_characters():
|
|
164
164
|
assert repair_json("""{ "a": "", "b": [ { "c": 1} ] \n}```""") == '{"a": "", "b": [{"c": 1}]}'
|
165
165
|
assert repair_json("Based on the information extracted, here is the filled JSON output: ```json { 'a': 'b' } ```") == '{"a": "b"}'
|
166
166
|
assert repair_json("""
|
167
|
+
The next 64 elements are:
|
167
168
|
```json
|
168
169
|
{ "key": "value" }
|
169
170
|
```""") == '{"key": "value"}'
|
@@ -19,7 +19,7 @@ def test_true_true_correct(benchmark):
|
|
19
19
|
mean_time = benchmark.stats.get("median")
|
20
20
|
|
21
21
|
# Define your time threshold in seconds
|
22
|
-
max_time =
|
22
|
+
max_time = 14 / 10 ** 4 # 1.4 millisecond
|
23
23
|
|
24
24
|
# Assert that the average time is below the threshold
|
25
25
|
assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
|
@@ -31,7 +31,7 @@ def test_true_true_incorrect(benchmark):
|
|
31
31
|
mean_time = benchmark.stats.get("median")
|
32
32
|
|
33
33
|
# Define your time threshold in seconds
|
34
|
-
max_time =
|
34
|
+
max_time = 14 / 10 ** 4 # 1.4 millisecond
|
35
35
|
|
36
36
|
# Assert that the average time is below the threshold
|
37
37
|
assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
|
@@ -53,7 +53,7 @@ def test_true_false_incorrect(benchmark):
|
|
53
53
|
mean_time = benchmark.stats.get("median")
|
54
54
|
|
55
55
|
# Define your time threshold in seconds
|
56
|
-
max_time =
|
56
|
+
max_time = 14 / 10 ** 4 # 1.4 millisecond
|
57
57
|
|
58
58
|
# Assert that the average time is below the threshold
|
59
59
|
assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|