json-repair 0.30.2__tar.gz → 0.31.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {json_repair-0.30.2/src/json_repair.egg-info → json_repair-0.31.0}/PKG-INFO +1 -1
- {json_repair-0.30.2 → json_repair-0.31.0}/pyproject.toml +1 -1
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair/json_parser.py +21 -1
- {json_repair-0.30.2 → json_repair-0.31.0/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.30.2 → json_repair-0.31.0}/tests/test_json_repair.py +3 -1
- {json_repair-0.30.2 → json_repair-0.31.0}/tests/test_performance.py +1 -1
- {json_repair-0.30.2 → json_repair-0.31.0}/LICENSE +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/README.md +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/setup.cfg +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair/__init__.py +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair/__main__.py +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair/json_context.py +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair/py.typed +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.30.2 → json_repair-0.31.0}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.30.2 → json_repair-0.31.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.31.0"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -322,11 +322,24 @@ class JSONParser:
|
|
322
322
|
else:
|
323
323
|
# OK but this could still be some garbage at the end of the string
|
324
324
|
# So we need to check if we find a new lstring_delimiter afterwards
|
325
|
-
# If we do, this is a missing delimiter
|
325
|
+
# If we do, maybe this is a missing delimiter
|
326
326
|
i = self.skip_to_character(character=lstring_delimiter, idx=i)
|
327
|
+
if doubled_quotes:
|
328
|
+
i = self.skip_to_character(
|
329
|
+
character=lstring_delimiter, idx=i
|
330
|
+
)
|
327
331
|
next_c = self.get_char_at(i)
|
328
332
|
if not next_c:
|
329
333
|
rstring_delimiter_missing = False
|
334
|
+
else:
|
335
|
+
# But again, this could just be something a bit stupid like "lorem, "ipsum" sic"
|
336
|
+
# Check if we find a : afterwards (skipping space)
|
337
|
+
i = self.skip_whitespaces_at(
|
338
|
+
idx=i + 1, move_main_index=False
|
339
|
+
)
|
340
|
+
next_c = self.get_char_at(i)
|
341
|
+
if next_c and next_c != ":":
|
342
|
+
rstring_delimiter_missing = False
|
330
343
|
else:
|
331
344
|
# There could be a case in which even the next key:value is missing delimeters
|
332
345
|
# because it might be a systemic issue with the output
|
@@ -362,6 +375,13 @@ class JSONParser:
|
|
362
375
|
"While parsing a string missing the left delimiter in object value context, we found a , or } and we couldn't determine that a right delimiter was present. Stopping here",
|
363
376
|
)
|
364
377
|
break
|
378
|
+
if char == "]" and ContextValues.ARRAY in self.context.context:
|
379
|
+
# We found the end of an array and we are in array context
|
380
|
+
# So let's check if we find a rstring_delimiter forward otherwise end early
|
381
|
+
i = self.skip_to_character(rstring_delimiter)
|
382
|
+
if not self.get_char_at(i):
|
383
|
+
# No delimiter found
|
384
|
+
break
|
365
385
|
string_acc += char
|
366
386
|
self.index += 1
|
367
387
|
char = self.get_char_at()
|
@@ -108,6 +108,7 @@ def test_missing_and_mixed_quotes():
|
|
108
108
|
assert repair_json('{"key": value "key2" : "value2" ') == '{"key": "value", "key2": "value2"}'
|
109
109
|
assert repair_json('{"key": "lorem ipsum ... "sic " tamet. ...}') == '{"key": "lorem ipsum ... \\"sic \\" tamet. ..."}'
|
110
110
|
assert repair_json('{"key": value , }') == '{"key": "value"}'
|
111
|
+
assert repair_json('{"comment": "lorem, "ipsum" sic "tamet". To improve"}') == '{"comment": "lorem, \\"ipsum\\" sic \\"tamet\\". To improve"}'
|
111
112
|
|
112
113
|
def test_array_edge_cases():
|
113
114
|
assert repair_json("[1, 2, 3,") == "[1, 2, 3]"
|
@@ -119,6 +120,7 @@ def test_array_edge_cases():
|
|
119
120
|
assert repair_json('{"employees":["John", "Anna",') == '{"employees": ["John", "Anna"]}'
|
120
121
|
assert repair_json('{"employees":["John", "Anna", "Peter') == '{"employees": ["John", "Anna", "Peter"]}'
|
121
122
|
assert repair_json('{"key1": {"key2": [1, 2, 3') == '{"key1": {"key2": [1, 2, 3]}}'
|
123
|
+
assert repair_json('{"key": ["value]}') == '{"key": ["value"]}'
|
122
124
|
|
123
125
|
def test_escaping():
|
124
126
|
assert repair_json("'\"'") == '""'
|
@@ -134,7 +136,7 @@ def test_object_edge_cases():
|
|
134
136
|
assert repair_json('{"value_1": true, COMMENT "value_2": "data"}') == '{"value_1": true, "value_2": "data"}'
|
135
137
|
assert repair_json('{"value_1": true, SHOULD_NOT_EXIST "value_2": "data" AAAA }') == '{"value_1": true, "value_2": "data"}'
|
136
138
|
assert repair_json('{"" : true, "key2": "value2"}') == '{"": true, "key2": "value2"}'
|
137
|
-
assert repair_json(
|
139
|
+
assert repair_json("""{""answer"":[{""traits"":''Female aged 60+'',""answer1"":""5""}]}""") == '{"answer": [{"traits": "Female aged 60+", "answer1": "5"}]}'
|
138
140
|
assert repair_json('{ "words": abcdef", "numbers": 12345", "words2": ghijkl" }') == '{"words": "abcdef", "numbers": 12345, "words2": "ghijkl"}'
|
139
141
|
assert repair_json('''{"number": 1,"reason": "According...""ans": "YES"}''') == '{"number": 1, "reason": "According...", "ans": "YES"}'
|
140
142
|
assert repair_json('''{ "a" : "{ b": {} }" }''') == '{"a": "{ b"}'
|
@@ -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 = 1.
|
100
|
+
max_time = 1.9 / 10 ** 3 # 1.9 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
|