json-repair 0.4.5__py3-none-any.whl → 0.5.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 +14 -8
- {json_repair-0.4.5.dist-info → json_repair-0.5.0.dist-info}/METADATA +2 -2
- json_repair-0.5.0.dist-info/RECORD +7 -0
- json_repair-0.4.5.dist-info/RECORD +0 -7
- {json_repair-0.4.5.dist-info → json_repair-0.5.0.dist-info}/LICENSE +0 -0
- {json_repair-0.4.5.dist-info → json_repair-0.5.0.dist-info}/WHEEL +0 -0
- {json_repair-0.4.5.dist-info → json_repair-0.5.0.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -61,6 +61,8 @@ class JSONParser:
|
|
61
61
|
# <string> starts with '"'
|
62
62
|
elif char == '"':
|
63
63
|
return self.parse_string()
|
64
|
+
elif char == "'":
|
65
|
+
return self.parse_string(use_single_quotes=True)
|
64
66
|
# <number> starts with [0-9] or minus
|
65
67
|
elif char.isdigit() or char == "-":
|
66
68
|
return self.parse_number()
|
@@ -105,7 +107,9 @@ class JSONParser:
|
|
105
107
|
# <member> starts with a <string>
|
106
108
|
key = ""
|
107
109
|
while key == "" and self.get_char_at():
|
108
|
-
key = self.parse_string(
|
110
|
+
key = self.parse_string(
|
111
|
+
use_single_quotes=(self.json_str[self.index] == "'")
|
112
|
+
)
|
109
113
|
|
110
114
|
# We reached the end here
|
111
115
|
if key == "}":
|
@@ -166,17 +170,19 @@ class JSONParser:
|
|
166
170
|
self.index += 1
|
167
171
|
return arr
|
168
172
|
|
169
|
-
def parse_string(self) -> str:
|
173
|
+
def parse_string(self, use_single_quotes=False) -> str:
|
170
174
|
# <string> is a string of valid characters enclosed in quotes
|
171
175
|
# i.e. { name: "John" }
|
172
176
|
# Somehow all weird cases in an invalid JSON happen to be resolved in this function, so be careful here
|
173
177
|
|
174
178
|
# Flag to manage corner cases related to missing starting quote
|
175
179
|
fixed_quotes = False
|
176
|
-
|
180
|
+
string_terminator = '"'
|
181
|
+
if use_single_quotes:
|
182
|
+
string_terminator = "'"
|
177
183
|
char = self.get_char_at()
|
178
|
-
if char !=
|
179
|
-
self.insert_char_at(
|
184
|
+
if char != string_terminator:
|
185
|
+
self.insert_char_at(string_terminator)
|
180
186
|
fixed_quotes = True
|
181
187
|
else:
|
182
188
|
self.index += 1
|
@@ -191,7 +197,7 @@ class JSONParser:
|
|
191
197
|
# * It iterated over the entire sequence
|
192
198
|
# * If we are fixing missing quotes in an object, when it finds the special terminators
|
193
199
|
char = self.get_char_at()
|
194
|
-
while char and char !=
|
200
|
+
while char and char != string_terminator:
|
195
201
|
if fixed_quotes:
|
196
202
|
if self.context == "object_key" and (char == ":" or char.isspace()):
|
197
203
|
break
|
@@ -208,8 +214,8 @@ class JSONParser:
|
|
208
214
|
end = self.index
|
209
215
|
|
210
216
|
# A fallout of the previous special case in the while loop, we need to update the index only if we had a closing quote
|
211
|
-
if char !=
|
212
|
-
self.insert_char_at(
|
217
|
+
if char != string_terminator:
|
218
|
+
self.insert_char_at(string_terminator)
|
213
219
|
else:
|
214
220
|
self.index += 1
|
215
221
|
|
@@ -0,0 +1,7 @@
|
|
1
|
+
json_repair/__init__.py,sha256=p9mZnte8Bg18NcxqgJ7vopH2gQv_XbZ0dRnk686QuRE,92
|
2
|
+
json_repair/json_repair.py,sha256=Hdevgq1_s8JaHCALBd7gTxp8_DexKezz8g6Cm0LcJTc,12505
|
3
|
+
json_repair-0.5.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
+
json_repair-0.5.0.dist-info/METADATA,sha256=6_UiFGc3X93VQ8tFU1y02b16fbMyRybrQu1B7wwBmL8,6011
|
5
|
+
json_repair-0.5.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
6
|
+
json_repair-0.5.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
+
json_repair-0.5.0.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=p9mZnte8Bg18NcxqgJ7vopH2gQv_XbZ0dRnk686QuRE,92
|
2
|
-
json_repair/json_repair.py,sha256=ezQraeyIucpwRgnh12S5m7Mn2eR5i0rKdwAkLrkAhEA,12136
|
3
|
-
json_repair-0.4.5.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
-
json_repair-0.4.5.dist-info/METADATA,sha256=C6GUgX3IMBJfr_kecH3ZD6jkjdgfgdI0S0vFnivHaK4,6011
|
5
|
-
json_repair-0.4.5.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
6
|
-
json_repair-0.4.5.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
-
json_repair-0.4.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|