json-repair 0.22.0__tar.gz → 0.23.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.22.0/src/json_repair.egg-info → json_repair-0.23.0}/PKG-INFO +1 -1
- {json_repair-0.22.0 → json_repair-0.23.0}/pyproject.toml +1 -1
- {json_repair-0.22.0 → json_repair-0.23.0}/src/json_repair/json_repair.py +20 -10
- {json_repair-0.22.0 → json_repair-0.23.0/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.22.0 → json_repair-0.23.0}/tests/test_json_repair.py +5 -0
- {json_repair-0.22.0 → json_repair-0.23.0}/LICENSE +0 -0
- {json_repair-0.22.0 → json_repair-0.23.0}/README.md +0 -0
- {json_repair-0.22.0 → json_repair-0.23.0}/setup.cfg +0 -0
- {json_repair-0.22.0 → json_repair-0.23.0}/src/json_repair/__init__.py +0 -0
- {json_repair-0.22.0 → json_repair-0.23.0}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.22.0 → json_repair-0.23.0}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.22.0 → json_repair-0.23.0}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.22.0 → json_repair-0.23.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.23.0"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -89,10 +89,25 @@ class JSONParser:
|
|
89
89
|
def parse(
|
90
90
|
self,
|
91
91
|
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]:
|
92
|
+
json = self.parse_json()
|
93
|
+
if self.index < len(self.json_str):
|
94
|
+
json = [json]
|
95
|
+
last_index = self.index
|
96
|
+
while self.index < len(self.json_str):
|
97
|
+
j = self.parse_json()
|
98
|
+
if j != "":
|
99
|
+
json.append(j)
|
100
|
+
if self.index == last_index:
|
101
|
+
self.index += 1
|
102
|
+
last_index = self.index
|
103
|
+
if len(json) == 1:
|
104
|
+
json = json[0]
|
105
|
+
elif len(json) == 0:
|
106
|
+
json = ""
|
92
107
|
if self.logger.log_level == "none":
|
93
|
-
return
|
108
|
+
return json
|
94
109
|
else:
|
95
|
-
return
|
110
|
+
return json, self.logger.log
|
96
111
|
|
97
112
|
def parse_json(
|
98
113
|
self,
|
@@ -306,14 +321,6 @@ class JSONParser:
|
|
306
321
|
"While parsing a string, we found a literal instead of a quote",
|
307
322
|
"info",
|
308
323
|
)
|
309
|
-
if self.get_context() == "":
|
310
|
-
# A string literal in the wild isn't a valid json and not something we can fix
|
311
|
-
self.log(
|
312
|
-
"While parsing a string, we found a literal outside of context, ignoring it",
|
313
|
-
"info",
|
314
|
-
)
|
315
|
-
self.index += 1
|
316
|
-
return self.parse_json()
|
317
324
|
self.log(
|
318
325
|
"While parsing a string, we found no starting quote. Will add the quote back",
|
319
326
|
"info",
|
@@ -658,3 +665,6 @@ def from_file(
|
|
658
665
|
fd.close()
|
659
666
|
|
660
667
|
return jsonobj
|
668
|
+
|
669
|
+
|
670
|
+
repair_json("[]{}")
|
@@ -168,6 +168,11 @@ def test_leading_trailing_characters():
|
|
168
168
|
```json
|
169
169
|
{ "key": "value" }
|
170
170
|
```""") == '{"key": "value"}'
|
171
|
+
def test_multiple_jsons():
|
172
|
+
assert repair_json("[]{}") == "[[], {}]"
|
173
|
+
assert repair_json("{}[]") == "[{}, []]"
|
174
|
+
assert repair_json('{"key":"value"}[1,2,3,True]') == '[{"key": "value"}, ["1,2,3", true]]'
|
175
|
+
assert repair_json('lorem ```json {"key":"value"} ``` ipsum ```json [1,2,3,True] ``` 42') == '[{"key": "value"}, ["1,2,3", true]]'
|
171
176
|
|
172
177
|
def test_repair_json_with_objects():
|
173
178
|
# Test with valid JSON strings
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|