json-repair 0.15.6__py3-none-any.whl → 0.16.0__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 +11 -8
- {json_repair-0.15.6.dist-info → json_repair-0.16.0.dist-info}/METADATA +1 -1
- json_repair-0.16.0.dist-info/RECORD +7 -0
- json_repair-0.15.6.dist-info/RECORD +0 -7
- {json_repair-0.15.6.dist-info → json_repair-0.16.0.dist-info}/LICENSE +0 -0
- {json_repair-0.15.6.dist-info → json_repair-0.16.0.dist-info}/WHEEL +0 -0
- {json_repair-0.15.6.dist-info → json_repair-0.16.0.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -64,7 +64,7 @@ class JSONParser:
|
|
64
64
|
return self.parse_array()
|
65
65
|
# there can be an edge case in which a key is empty and at the end of an object
|
66
66
|
# like "key": }. We return an empty string here to close the object properly
|
67
|
-
elif char == "}"
|
67
|
+
elif char == "}":
|
68
68
|
self.log(
|
69
69
|
"At the end of an object we found a key with missing value, skipping",
|
70
70
|
"info",
|
@@ -78,13 +78,13 @@ class JSONParser:
|
|
78
78
|
elif char == "“":
|
79
79
|
return self.parse_string(string_quotes=["“", "”"])
|
80
80
|
# <number> starts with [0-9] or minus
|
81
|
-
elif char.isdigit() or char == "-" or char == ".":
|
81
|
+
elif self.get_context() != "" and char.isdigit() or char == "-" or char == ".":
|
82
82
|
return self.parse_number()
|
83
83
|
# <boolean> could be (T)rue or (F)alse or (N)ull
|
84
|
-
elif char.lower() in ["t", "f", "n"]:
|
84
|
+
elif self.get_context() != "" and char.lower() in ["t", "f", "n"]:
|
85
85
|
return self.parse_boolean_or_null()
|
86
86
|
# This might be a <string> that is missing the starting '"'
|
87
|
-
elif char.isalpha():
|
87
|
+
elif self.get_context() != "" and char.isalpha():
|
88
88
|
return self.parse_string()
|
89
89
|
# If everything else fails, we just ignore and move on
|
90
90
|
else:
|
@@ -131,6 +131,8 @@ class JSONParser:
|
|
131
131
|
"info",
|
132
132
|
)
|
133
133
|
break
|
134
|
+
elif key == "":
|
135
|
+
self.index += 1
|
134
136
|
|
135
137
|
# We reached the end here
|
136
138
|
if (self.get_char_at() or "}") == "}":
|
@@ -172,6 +174,7 @@ class JSONParser:
|
|
172
174
|
def parse_array(self) -> List[Any]:
|
173
175
|
# <array> ::= '[' [ <json> *(', ' <json>) ] ']' ; A sequence of JSON values separated by commas
|
174
176
|
arr = []
|
177
|
+
self.set_context("array")
|
175
178
|
# Stop when you either find the closing parentheses or you have iterated over the entire string
|
176
179
|
while (self.get_char_at() or "]") != "]":
|
177
180
|
self.skip_whitespaces_at()
|
@@ -210,6 +213,7 @@ class JSONParser:
|
|
210
213
|
self.index -= 1
|
211
214
|
|
212
215
|
self.index += 1
|
216
|
+
self.reset_context()
|
213
217
|
return arr
|
214
218
|
|
215
219
|
def parse_string(self, string_quotes=False) -> str:
|
@@ -294,14 +298,13 @@ class JSONParser:
|
|
294
298
|
else:
|
295
299
|
# Check if eventually there is a rstring delimiter, otherwise we bail
|
296
300
|
i = 1
|
297
|
-
context = self.get_context()
|
298
301
|
next_c = self.get_char_at(i)
|
299
302
|
while next_c and next_c != rstring_delimiter:
|
300
303
|
# If we are in an object context, let's check for the right delimiters
|
301
304
|
if (
|
302
|
-
(
|
303
|
-
or (
|
304
|
-
or (
|
305
|
+
("object_key" in self.context and next_c == ":")
|
306
|
+
or ("object_value" in self.context and next_c in ["}", ","])
|
307
|
+
or ("array" in self.context and next_c in ["]", ","])
|
305
308
|
):
|
306
309
|
break
|
307
310
|
i += 1
|
@@ -0,0 +1,7 @@
|
|
1
|
+
json_repair/__init__.py,sha256=AlNie5y6BZBioGi5fzTAUvum_y0U5aL5aNsuQ_68LQc,175
|
2
|
+
json_repair/json_repair.py,sha256=XahLp82VVwg8KgyywNxMFBHIPIbvPDp6uWMP1VD_40w,20418
|
3
|
+
json_repair-0.16.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
+
json_repair-0.16.0.dist-info/METADATA,sha256=-OLuKPGwu4enrP7kP2947Gyz9l7JRVpGTRH1b1MB2ZY,7355
|
5
|
+
json_repair-0.16.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
json_repair-0.16.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
+
json_repair-0.16.0.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=AlNie5y6BZBioGi5fzTAUvum_y0U5aL5aNsuQ_68LQc,175
|
2
|
-
json_repair/json_repair.py,sha256=qQosSMpX3r1adMubgHNZ9gT0lSlZBn3Id_98yS1ITwk,20270
|
3
|
-
json_repair-0.15.6.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
-
json_repair-0.15.6.dist-info/METADATA,sha256=BNtrdGCSn8NC9gBrWdmX2bRQv6VJgEcwgCM5_SWLXUY,7355
|
5
|
-
json_repair-0.15.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
json_repair-0.15.6.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
-
json_repair-0.15.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|