json-repair 0.34.0__tar.gz → 0.36.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {json_repair-0.34.0/src/json_repair.egg-info → json_repair-0.36.0}/PKG-INFO +2 -2
- {json_repair-0.34.0 → json_repair-0.36.0}/pyproject.toml +1 -1
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair/json_parser.py +36 -0
- {json_repair-0.34.0 → json_repair-0.36.0/src/json_repair.egg-info}/PKG-INFO +2 -2
- {json_repair-0.34.0 → json_repair-0.36.0}/tests/test_json_repair.py +4 -1
- {json_repair-0.34.0 → json_repair-0.36.0}/tests/test_performance.py +1 -1
- {json_repair-0.34.0 → json_repair-0.36.0}/LICENSE +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/README.md +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/setup.cfg +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair/__init__.py +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair/__main__.py +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair/json_context.py +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair/py.typed +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.34.0 → json_repair-0.36.0}/tests/test_coverage.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.36.0"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -223,6 +223,10 @@ class JSONParser:
|
|
223
223
|
"While parsing an array we missed the closing ], adding it back",
|
224
224
|
)
|
225
225
|
self.index -= 1
|
226
|
+
# Add the missing closing bracket
|
227
|
+
self.json_str = (
|
228
|
+
self.json_str[: self.index + 1] + "]" + self.json_str[self.index + 1 :]
|
229
|
+
)
|
226
230
|
|
227
231
|
self.index += 1
|
228
232
|
self.context.reset()
|
@@ -443,6 +447,38 @@ class JSONParser:
|
|
443
447
|
string_acc += escape_seqs.get(char, char) or char
|
444
448
|
self.index += 1
|
445
449
|
char = self.get_char_at()
|
450
|
+
# If we are in object key context and we find a colon, it could be a missing right quote
|
451
|
+
if (
|
452
|
+
char == ":"
|
453
|
+
and not missing_quotes
|
454
|
+
and self.context.current == ContextValues.OBJECT_KEY
|
455
|
+
):
|
456
|
+
# Ok now we need to check if this is followed by a value like "..."
|
457
|
+
i = self.skip_to_character(character=lstring_delimiter, idx=1)
|
458
|
+
next_c = self.get_char_at(i)
|
459
|
+
if next_c:
|
460
|
+
i += 1
|
461
|
+
# found the first delimiter
|
462
|
+
i = self.skip_to_character(character=rstring_delimiter, idx=i)
|
463
|
+
next_c = self.get_char_at(i)
|
464
|
+
if next_c:
|
465
|
+
# found a second delimiter
|
466
|
+
i += 1
|
467
|
+
# Skip spaces
|
468
|
+
i = self.skip_whitespaces_at(idx=i, move_main_index=False)
|
469
|
+
next_c = self.get_char_at(i)
|
470
|
+
if next_c and next_c in [",", "}"]:
|
471
|
+
# Ok then this is a missing right quote
|
472
|
+
self.log(
|
473
|
+
"While parsing a string missing the right delimiter in object key context, we found a :, stopping here",
|
474
|
+
)
|
475
|
+
break
|
476
|
+
else:
|
477
|
+
# The string ended without finding a lstring_delimiter, I will assume this is a missing right quote
|
478
|
+
self.log(
|
479
|
+
"While parsing a string missing the right delimiter in object key context, we found a :, stopping here",
|
480
|
+
)
|
481
|
+
break
|
446
482
|
# ChatGPT sometimes forget to quote stuff in html tags or markdown, so we do this whole thing here
|
447
483
|
if char == rstring_delimiter:
|
448
484
|
# Special case here, in case of double quotes one after another
|
@@ -122,7 +122,8 @@ def test_array_edge_cases():
|
|
122
122
|
assert repair_json('{"key1": {"key2": [1, 2, 3') == '{"key1": {"key2": [1, 2, 3]}}'
|
123
123
|
assert repair_json('{"key": ["value]}') == '{"key": ["value"]}'
|
124
124
|
assert repair_json('["lorem "ipsum" sic"]') == '["lorem \\"ipsum\\" sic"]'
|
125
|
-
|
125
|
+
assert repair_json('{"key1": ["value1", "value2"}, "key2": ["value3", "value4"]}') == '{"key1": ["value1", "value2"], "key2": ["value3", "value4"]}'
|
126
|
+
|
126
127
|
def test_escaping():
|
127
128
|
assert repair_json("'\"'") == '""'
|
128
129
|
assert repair_json("{\"key\": 'string\"\n\t\le'") == '{"key": "string\\"\\n\\t\\\\le"}'
|
@@ -153,6 +154,8 @@ def test_object_edge_cases():
|
|
153
154
|
assert repair_json('{text:words{words in brackets}m}') == '{"text": "words{words in brackets}m"}'
|
154
155
|
assert repair_json('{"key": "value, value2"```') == '{"key": "value, value2"}'
|
155
156
|
assert repair_json('{key:value,key2:value2}') == '{"key": "value", "key2": "value2"}'
|
157
|
+
assert repair_json('{"key:"value"}') == '{"key": "value"}'
|
158
|
+
assert repair_json('{"key:value}') == '{"key": "value"}'
|
156
159
|
assert repair_json('[{"lorem": {"ipsum": "sic"}, """" "lorem": {"ipsum": "sic"}]') == '[{"lorem": {"ipsum": "sic"}}, {"lorem": {"ipsum": "sic"}}]'
|
157
160
|
|
158
161
|
def test_number_edge_cases():
|
@@ -97,7 +97,7 @@ def test_false_false_incorrect(benchmark):
|
|
97
97
|
mean_time = benchmark.stats.get("median")
|
98
98
|
|
99
99
|
# Define your time threshold in seconds
|
100
|
-
max_time =
|
100
|
+
max_time = 2 / 10 ** 3 # 2 millisecond
|
101
101
|
|
102
102
|
# Assert that the average time is below the threshold
|
103
103
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|