json-repair 0.6.1__py3-none-any.whl → 0.6.2__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_repair.py +8 -22
- {json_repair-0.6.1.dist-info → json_repair-0.6.2.dist-info}/METADATA +1 -1
- json_repair-0.6.2.dist-info/RECORD +7 -0
- json_repair-0.6.1.dist-info/RECORD +0 -7
- {json_repair-0.6.1.dist-info → json_repair-0.6.2.dist-info}/LICENSE +0 -0
- {json_repair-0.6.1.dist-info → json_repair-0.6.2.dist-info}/WHEEL +0 -0
- {json_repair-0.6.1.dist-info → json_repair-0.6.2.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -207,17 +207,18 @@ class JSONParser:
|
|
207
207
|
if fixed_quotes:
|
208
208
|
if self.context == "object_key" and (char == ":" or char.isspace()):
|
209
209
|
break
|
210
|
-
elif self.context == "object_value" and
|
210
|
+
elif self.context == "object_value" and char in [",", "}"]:
|
211
211
|
break
|
212
212
|
self.index += 1
|
213
213
|
char = self.get_char_at()
|
214
214
|
# ChatGPT sometimes forget to quote links in markdown like: { "content": "[LINK]("https://google.com")" }
|
215
215
|
if (
|
216
216
|
char == string_terminator
|
217
|
-
|
217
|
+
# Next character is not a comma
|
218
|
+
and self.get_char_at(1) != ","
|
218
219
|
and (
|
219
220
|
fix_broken_markdown_link
|
220
|
-
or (self.
|
221
|
+
or (self.get_char_at(-2) == "]" and self.get_char_at(-1)) == "("
|
221
222
|
)
|
222
223
|
):
|
223
224
|
fix_broken_markdown_link = not fix_broken_markdown_link
|
@@ -239,7 +240,7 @@ class JSONParser:
|
|
239
240
|
|
240
241
|
return self.json_str[start:end]
|
241
242
|
|
242
|
-
def parse_number(self) -> Union[float, int]:
|
243
|
+
def parse_number(self) -> Union[float, int, str]:
|
243
244
|
# <number> is a valid real number expressed in one of a number of given formats
|
244
245
|
number_str = ""
|
245
246
|
number_chars = set("0123456789-.eE")
|
@@ -257,7 +258,7 @@ class JSONParser:
|
|
257
258
|
# This is a string then
|
258
259
|
return self.parse_string()
|
259
260
|
|
260
|
-
def parse_boolean_or_null(self) -> Union[bool, None]:
|
261
|
+
def parse_boolean_or_null(self) -> Union[bool, str, None]:
|
261
262
|
# <boolean> is one of the literal strings 'true', 'false', or 'null' (unquoted)
|
262
263
|
boolean_map = {"true": (True, 4), "false": (False, 5), "null": (None, 4)}
|
263
264
|
for key, (value, length) in boolean_map.items():
|
@@ -272,21 +273,7 @@ class JSONParser:
|
|
272
273
|
self.json_str = self.json_str[: self.index] + char + self.json_str[self.index :]
|
273
274
|
self.index += 1
|
274
275
|
|
275
|
-
def get_char_at(self) -> Union[str, bool]:
|
276
|
-
# Why not use something simpler? Because we might be out of bounds and doing this check all the time is annoying
|
277
|
-
try:
|
278
|
-
return self.json_str[self.index]
|
279
|
-
except IndexError:
|
280
|
-
return False
|
281
|
-
|
282
|
-
def get_prev_char(self, count=1):
|
283
|
-
# Why not use something simpler? Because we might be out of bounds and doing this check all the time is annoying
|
284
|
-
try:
|
285
|
-
return self.json_str[self.index - count]
|
286
|
-
except IndexError:
|
287
|
-
return False
|
288
|
-
|
289
|
-
def get_next_char(self, count=1):
|
276
|
+
def get_char_at(self, count: int = 0) -> Union[str, bool]:
|
290
277
|
# Why not use something simpler? Because we might be out of bounds and doing this check all the time is annoying
|
291
278
|
try:
|
292
279
|
return self.json_str[self.index + count]
|
@@ -320,8 +307,7 @@ def repair_json(
|
|
320
307
|
It will return the fixed string by default.
|
321
308
|
When `return_objects=True` is passed, it will return the decoded data structure instead.
|
322
309
|
"""
|
323
|
-
json_str =
|
324
|
-
json_str = re.sub(r"\s+$", "", json_str)
|
310
|
+
json_str = json_str.strip()
|
325
311
|
json_str = re.sub(r"/\*.*?\*/", "", json_str)
|
326
312
|
parser = JSONParser(json_str)
|
327
313
|
if skip_json_loads:
|
@@ -0,0 +1,7 @@
|
|
1
|
+
json_repair/__init__.py,sha256=p9mZnte8Bg18NcxqgJ7vopH2gQv_XbZ0dRnk686QuRE,92
|
2
|
+
json_repair/json_repair.py,sha256=Zk5JFdO7n5SyDZZ8SUEFJp6--ey5Pa-jlpXEBzwqtJQ,13311
|
3
|
+
json_repair-0.6.2.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
+
json_repair-0.6.2.dist-info/METADATA,sha256=6zUF2tGJnxPzvog3uw_v9970mx6MgccC4X46ScJHcxQ,6011
|
5
|
+
json_repair-0.6.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
6
|
+
json_repair-0.6.2.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
+
json_repair-0.6.2.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=p9mZnte8Bg18NcxqgJ7vopH2gQv_XbZ0dRnk686QuRE,92
|
2
|
-
json_repair/json_repair.py,sha256=ytH0gCY-h9YtQSI_5RM0032MdyrgiYgXG5bUqukxJJA,13847
|
3
|
-
json_repair-0.6.1.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
-
json_repair-0.6.1.dist-info/METADATA,sha256=OaB_CHIyIKJR6CA6Yd0lWU_keWIwtOMGQSM6LLk0n5k,6011
|
5
|
-
json_repair-0.6.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
6
|
-
json_repair-0.6.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
-
json_repair-0.6.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|