json-repair 0.52.0__tar.gz → 0.52.1__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.52.0/src/json_repair.egg-info → json_repair-0.52.1}/PKG-INFO +1 -1
- {json_repair-0.52.0 → json_repair-0.52.1}/pyproject.toml +1 -1
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/json_parser.py +1 -1
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/parse_string.py +12 -2
- {json_repair-0.52.0 → json_repair-0.52.1/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_parse_object.py +1 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/LICENSE +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/README.md +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/setup.cfg +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/__init__.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/__main__.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/constants.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/json_context.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/object_comparer.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/parse_array.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/parse_boolean_or_null.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/parse_comment.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/parse_number.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/parse_object.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/py.typed +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_json_repair.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_parse_array.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_parse_boolean_or_null.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_parse_comment.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_parse_number.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_parse_string.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_performance.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_repair_json_cli.py +0 -0
- {json_repair-0.52.0 → json_repair-0.52.1}/tests/test_repair_json_from_file.py +0 -0
|
@@ -155,7 +155,7 @@ class JSONParser:
|
|
|
155
155
|
return idx
|
|
156
156
|
return idx
|
|
157
157
|
|
|
158
|
-
def skip_to_character(self, character: str | list, idx: int = 0) -> int:
|
|
158
|
+
def skip_to_character(self, character: str | list[str], idx: int = 0) -> int:
|
|
159
159
|
"""
|
|
160
160
|
This function quickly iterates to find a character, syntactic sugar to make the code more concise
|
|
161
161
|
"""
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
from typing import TYPE_CHECKING
|
|
2
2
|
|
|
3
|
-
from .constants import STRING_DELIMITERS
|
|
3
|
+
from .constants import STRING_DELIMITERS, JSONReturnType
|
|
4
4
|
from .json_context import ContextValues
|
|
5
5
|
|
|
6
6
|
if TYPE_CHECKING:
|
|
7
7
|
from .json_parser import JSONParser
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def parse_string(self: "JSONParser") ->
|
|
10
|
+
def parse_string(self: "JSONParser") -> JSONReturnType:
|
|
11
11
|
# <string> is a string of valid characters enclosed in quotes
|
|
12
12
|
# i.e. { name: "John" }
|
|
13
13
|
# Somehow all weird cases in an invalid JSON happen to be resolved in this function, so be careful here
|
|
@@ -201,6 +201,16 @@ def parse_string(self: "JSONParser") -> str | bool | None:
|
|
|
201
201
|
if not self.get_char_at(i):
|
|
202
202
|
# No delimiter found
|
|
203
203
|
break
|
|
204
|
+
if self.context.current == ContextValues.OBJECT_VALUE and char == "}":
|
|
205
|
+
# We found the end of an object while parsing a value
|
|
206
|
+
# Check if the object is really over, to avoid doubling the closing brace
|
|
207
|
+
i = self.skip_whitespaces_at(idx=1, move_main_index=False)
|
|
208
|
+
next_c = self.get_char_at(i)
|
|
209
|
+
if not next_c:
|
|
210
|
+
self.log(
|
|
211
|
+
"While parsing a string in object value context, we found a } that closes the object, stopping here",
|
|
212
|
+
)
|
|
213
|
+
break
|
|
204
214
|
string_acc += char
|
|
205
215
|
self.index += 1
|
|
206
216
|
char = self.get_char_at()
|
|
@@ -23,6 +23,7 @@ def test_parse_object():
|
|
|
23
23
|
def test_parse_object_edge_cases():
|
|
24
24
|
assert repair_json("{foo: [}") == '{"foo": []}'
|
|
25
25
|
assert repair_json('{"": "value"') == '{"": "value"}'
|
|
26
|
+
assert repair_json('{"key": "v"alue"}') == '{"key": "v\\"alue\\""}'
|
|
26
27
|
assert repair_json('{"value_1": true, COMMENT "value_2": "data"}') == '{"value_1": true, "value_2": "data"}'
|
|
27
28
|
assert (
|
|
28
29
|
repair_json('{"value_1": true, SHOULD_NOT_EXIST "value_2": "data" AAAA }')
|
|
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
|
|
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
|
|
File without changes
|