json-repair 0.51.0__py3-none-any.whl → 0.52.1__py3-none-any.whl
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/json_parser.py +1 -1
- json_repair/parse_object.py +7 -0
- json_repair/parse_string.py +12 -2
- {json_repair-0.51.0.dist-info → json_repair-0.52.1.dist-info}/METADATA +1 -1
- {json_repair-0.51.0.dist-info → json_repair-0.52.1.dist-info}/RECORD +9 -9
- {json_repair-0.51.0.dist-info → json_repair-0.52.1.dist-info}/WHEEL +0 -0
- {json_repair-0.51.0.dist-info → json_repair-0.52.1.dist-info}/entry_points.txt +0 -0
- {json_repair-0.51.0.dist-info → json_repair-0.52.1.dist-info}/licenses/LICENSE +0 -0
- {json_repair-0.51.0.dist-info → json_repair-0.52.1.dist-info}/top_level.txt +0 -0
json_repair/json_parser.py
CHANGED
|
@@ -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
|
"""
|
json_repair/parse_object.py
CHANGED
|
@@ -10,6 +10,7 @@ if TYPE_CHECKING:
|
|
|
10
10
|
def parse_object(self: "JSONParser") -> dict[str, JSONReturnType]:
|
|
11
11
|
# <object> ::= '{' [ <member> *(', ' <member>) ] '}' ; A sequence of 'members'
|
|
12
12
|
obj: dict[str, JSONReturnType] = {}
|
|
13
|
+
start_index = self.index
|
|
13
14
|
# Stop when you either find the closing parentheses or you have iterated over the entire string
|
|
14
15
|
while (self.get_char_at() or "}") != "}":
|
|
15
16
|
# This is what we expect to find:
|
|
@@ -113,6 +114,12 @@ def parse_object(self: "JSONParser") -> dict[str, JSONReturnType]:
|
|
|
113
114
|
|
|
114
115
|
self.index += 1
|
|
115
116
|
|
|
117
|
+
# If the object is empty but also isn't just {}
|
|
118
|
+
if not obj and self.index - start_index > 2:
|
|
119
|
+
self.log("Parsed object is empty, we will try to parse this as an array instead")
|
|
120
|
+
self.index = start_index
|
|
121
|
+
return self.parse_array()
|
|
122
|
+
|
|
116
123
|
# Check if there are more key-value pairs after the closing brace
|
|
117
124
|
# This handles cases like '{"key": "value"}, "key2": "value2"}'
|
|
118
125
|
# But only if we're not in a nested context
|
json_repair/parse_string.py
CHANGED
|
@@ -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()
|
|
@@ -2,20 +2,20 @@ json_repair/__init__.py,sha256=JdJIZNCKV3MfIviryqK8NH8yGssCta2-192CekcwH-o,174
|
|
|
2
2
|
json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
|
|
3
3
|
json_repair/constants.py,sha256=cv2gvyosuq0me0600WyTysM9avrtfXPuXYR26tawcuo,158
|
|
4
4
|
json_repair/json_context.py,sha256=WsMOjqpGSr6aaDONcrk8UFtTurzWon2Qq9AoBBYseoI,934
|
|
5
|
-
json_repair/json_parser.py,sha256=
|
|
5
|
+
json_repair/json_parser.py,sha256=E5_xTtkLy4cNo2bgsBuGkQkpaL7NqJgODgWU_9rCEmE,7637
|
|
6
6
|
json_repair/json_repair.py,sha256=sDhXzDZxu0QmaFzICPTtf_q7yOY1A1Lf_iQG6Potsco,11572
|
|
7
7
|
json_repair/object_comparer.py,sha256=XKV3MRab8H7_v4sm-wpEa5le0XX9OeycWo5S-MFm-GI,1716
|
|
8
8
|
json_repair/parse_array.py,sha256=-rh65JcfT-FtXiR6s8RYlMfI-6LzVr08ytlDh6Z2CFE,2181
|
|
9
9
|
json_repair/parse_boolean_or_null.py,sha256=WMSkvvxsp4wvauBcDqtt9WnLMD5SMoxeRfZFXp3FEBc,890
|
|
10
10
|
json_repair/parse_comment.py,sha256=JHtQ_QlxOvPNnMh7lhUaoTjFGelqjhTNq7qn9xUE7SU,2648
|
|
11
11
|
json_repair/parse_number.py,sha256=33zAtkbuVzi9Lqjxu7cXn9WlVzd3WjRx9Ln_LFzVL4o,1259
|
|
12
|
-
json_repair/parse_object.py,sha256=
|
|
13
|
-
json_repair/parse_string.py,sha256=
|
|
12
|
+
json_repair/parse_object.py,sha256=xMpO64sYW0JmUtW75BTD0EdPQjY7PYVgu4tHVXrWB6s,5582
|
|
13
|
+
json_repair/parse_string.py,sha256=1vT1mRGaNPU0wvwv0D3uBlA-Rtv1DI8r5rld-xLUx74,24950
|
|
14
14
|
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
json_repair/string_file_wrapper.py,sha256=tGkWBEUPE-CZPf4uSM5NE9oSDTpskX0myJiXsl-gbds,4333
|
|
16
|
-
json_repair-0.
|
|
17
|
-
json_repair-0.
|
|
18
|
-
json_repair-0.
|
|
19
|
-
json_repair-0.
|
|
20
|
-
json_repair-0.
|
|
21
|
-
json_repair-0.
|
|
16
|
+
json_repair-0.52.1.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
|
17
|
+
json_repair-0.52.1.dist-info/METADATA,sha256=1W1OMlwVKBq05NIbazEZMnXQJXsMbosqmaYotZBYnGM,11027
|
|
18
|
+
json_repair-0.52.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
json_repair-0.52.1.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
|
20
|
+
json_repair-0.52.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
|
21
|
+
json_repair-0.52.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|