json-repair 0.30.1__tar.gz → 0.30.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {json_repair-0.30.1/src/json_repair.egg-info → json_repair-0.30.3}/PKG-INFO +1 -3
- {json_repair-0.30.1 → json_repair-0.30.3}/README.md +0 -2
- {json_repair-0.30.1 → json_repair-0.30.3}/pyproject.toml +1 -1
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair/json_parser.py +36 -20
- {json_repair-0.30.1 → json_repair-0.30.3/src/json_repair.egg-info}/PKG-INFO +1 -3
- {json_repair-0.30.1 → json_repair-0.30.3}/tests/test_json_repair.py +2 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/tests/test_performance.py +1 -1
- {json_repair-0.30.1 → json_repair-0.30.3}/LICENSE +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/setup.cfg +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair/__init__.py +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair/__main__.py +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair/json_context.py +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair/py.typed +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.30.1 → json_repair-0.30.3}/tests/test_coverage.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.30.
|
3
|
+
Version: 0.30.3
|
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
|
@@ -45,8 +45,6 @@ License-File: LICENSE
|
|
45
45
|
|
46
46
|
This simple package can be used to fix an invalid json string. To know all cases in which this package will work, check out the unit test.
|
47
47
|
|
48
|
-
Inspired by https://github.com/josdejong/jsonrepair
|
49
|
-
|
50
48
|

|
51
49
|
|
52
50
|
---
|
@@ -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.30.
|
6
|
+
version = "0.30.3"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -328,31 +328,47 @@ class JSONParser:
|
|
328
328
|
if not next_c:
|
329
329
|
rstring_delimiter_missing = False
|
330
330
|
else:
|
331
|
-
#
|
332
|
-
|
333
|
-
#
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
#
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
331
|
+
# There could be a case in which even the next key:value is missing delimeters
|
332
|
+
# because it might be a systemic issue with the output
|
333
|
+
# So let's check if we can find a : in the string instead
|
334
|
+
i = self.skip_to_character(character=":", idx=1)
|
335
|
+
next_c = self.get_char_at(i)
|
336
|
+
if next_c:
|
337
|
+
# OK then this is a systemic issue with the output
|
338
|
+
break
|
339
|
+
else:
|
340
|
+
# skip any whitespace first
|
341
|
+
i = self.skip_whitespaces_at(idx=1, move_main_index=False)
|
342
|
+
# We couldn't find any rstring_delimeter before the end of the string
|
343
|
+
# check if this is the last string of an object and therefore we can keep going
|
344
|
+
# make an exception if this is the last char before the closing brace
|
345
|
+
j = self.skip_to_character(character="}", idx=i)
|
346
|
+
if j - i > 1:
|
347
|
+
# Ok it's not right after the comma
|
348
|
+
# Let's ignore
|
349
|
+
rstring_delimiter_missing = False
|
350
|
+
# Check that j was not out of bound
|
351
|
+
elif self.get_char_at(j):
|
352
|
+
# Check for an unmatched opening brace in string_acc
|
353
|
+
for c in reversed(string_acc):
|
354
|
+
if c == "{":
|
355
|
+
# Ok then this is part of the string
|
356
|
+
rstring_delimiter_missing = False
|
357
|
+
break
|
358
|
+
elif c == "}":
|
359
|
+
break
|
351
360
|
if rstring_delimiter_missing:
|
352
361
|
self.log(
|
353
362
|
"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",
|
354
363
|
)
|
355
364
|
break
|
365
|
+
if char == "]" and ContextValues.ARRAY in self.context.context:
|
366
|
+
# We found the end of an array and we are in array context
|
367
|
+
# So let's check if we find a rstring_delimiter forward otherwise end early
|
368
|
+
i = self.skip_to_character(rstring_delimiter)
|
369
|
+
if not self.get_char_at(i):
|
370
|
+
# No delimiter found
|
371
|
+
break
|
356
372
|
string_acc += char
|
357
373
|
self.index += 1
|
358
374
|
char = self.get_char_at()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.30.
|
3
|
+
Version: 0.30.3
|
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
|
@@ -45,8 +45,6 @@ License-File: LICENSE
|
|
45
45
|
|
46
46
|
This simple package can be used to fix an invalid json string. To know all cases in which this package will work, check out the unit test.
|
47
47
|
|
48
|
-
Inspired by https://github.com/josdejong/jsonrepair
|
49
|
-
|
50
48
|

|
51
49
|
|
52
50
|
---
|
@@ -119,6 +119,7 @@ def test_array_edge_cases():
|
|
119
119
|
assert repair_json('{"employees":["John", "Anna",') == '{"employees": ["John", "Anna"]}'
|
120
120
|
assert repair_json('{"employees":["John", "Anna", "Peter') == '{"employees": ["John", "Anna", "Peter"]}'
|
121
121
|
assert repair_json('{"key1": {"key2": [1, 2, 3') == '{"key1": {"key2": [1, 2, 3]}}'
|
122
|
+
assert repair_json('{"key": ["value]}') == '{"key": ["value"]}'
|
122
123
|
|
123
124
|
def test_escaping():
|
124
125
|
assert repair_json("'\"'") == '""'
|
@@ -149,6 +150,7 @@ def test_object_edge_cases():
|
|
149
150
|
assert repair_json('{text:words{words in brackets}}') == '{"text": "words{words in brackets}"}'
|
150
151
|
assert repair_json('{text:words{words in brackets}m}') == '{"text": "words{words in brackets}m"}'
|
151
152
|
assert repair_json('{"key": "value, value2"```') == '{"key": "value, value2"}'
|
153
|
+
assert repair_json('{key:value,key2:value2}') == '{"key": "value", "key2": "value2"}'
|
152
154
|
|
153
155
|
def test_number_edge_cases():
|
154
156
|
assert repair_json(' - { "test_key": ["test_value", "test_value2"] }') == '{"test_key": ["test_value", "test_value2"]}'
|
@@ -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
|