json-repair 0.13.1__py3-none-any.whl → 0.14.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 +20 -16
- {json_repair-0.13.1.dist-info → json_repair-0.14.0.dist-info}/METADATA +5 -2
- json_repair-0.14.0.dist-info/RECORD +7 -0
- json_repair-0.13.1.dist-info/RECORD +0 -7
- {json_repair-0.13.1.dist-info → json_repair-0.14.0.dist-info}/LICENSE +0 -0
- {json_repair-0.13.1.dist-info → json_repair-0.14.0.dist-info}/WHEEL +0 -0
- {json_repair-0.13.1.dist-info → json_repair-0.14.0.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -183,15 +183,14 @@ class JSONParser:
|
|
183
183
|
|
184
184
|
# Flag to manage corner cases related to missing starting quote
|
185
185
|
fixed_quotes = False
|
186
|
-
double_delimiter = False
|
187
186
|
lstring_delimiter = rstring_delimiter = '"'
|
188
187
|
if isinstance(string_quotes, list):
|
189
188
|
lstring_delimiter = string_quotes[0]
|
190
189
|
rstring_delimiter = string_quotes[1]
|
191
190
|
elif isinstance(string_quotes, str):
|
192
191
|
lstring_delimiter = rstring_delimiter = string_quotes
|
192
|
+
# There is sometimes a weird case of doubled quotes, we manage this also later in the while loop
|
193
193
|
if self.get_char_at(1) == lstring_delimiter:
|
194
|
-
double_delimiter = True
|
195
194
|
self.index += 1
|
196
195
|
char = self.get_char_at()
|
197
196
|
if char != lstring_delimiter:
|
@@ -210,7 +209,6 @@ class JSONParser:
|
|
210
209
|
# * It iterated over the entire sequence
|
211
210
|
# * If we are fixing missing quotes in an object, when it finds the special terminators
|
212
211
|
char = self.get_char_at()
|
213
|
-
fix_broken_markdown_link = False
|
214
212
|
while char and char != rstring_delimiter:
|
215
213
|
if fixed_quotes:
|
216
214
|
if self.context == "object_key" and (char == ":" or char.isspace()):
|
@@ -227,19 +225,27 @@ class JSONParser:
|
|
227
225
|
else:
|
228
226
|
self.remove_char_at(-1)
|
229
227
|
self.index -= 1
|
230
|
-
# ChatGPT sometimes forget to quote
|
228
|
+
# ChatGPT sometimes forget to quote stuff in html tags or markdown, so we do this whole thing here
|
231
229
|
if (
|
232
230
|
char == rstring_delimiter
|
233
|
-
# Next character is not a
|
234
|
-
and self.get_char_at(1)
|
235
|
-
and (
|
236
|
-
fix_broken_markdown_link
|
237
|
-
or (self.get_char_at(-2) == "]" and self.get_char_at(-1)) == "("
|
238
|
-
)
|
231
|
+
# Next character is not a delimiter
|
232
|
+
and self.get_char_at(1) not in [",", ":", "]", "}"]
|
239
233
|
):
|
240
|
-
|
241
|
-
self.
|
242
|
-
|
234
|
+
# Special case here, in case of double quotes one after another
|
235
|
+
if self.get_char_at(1) == rstring_delimiter:
|
236
|
+
# self destruct this character
|
237
|
+
self.remove_char_at()
|
238
|
+
else:
|
239
|
+
# Check if eventually there is a rstring delimiter, otherwise we bail
|
240
|
+
i = 2
|
241
|
+
next_c = self.get_char_at(i)
|
242
|
+
while next_c and next_c != rstring_delimiter:
|
243
|
+
i += 1
|
244
|
+
next_c = self.get_char_at(i)
|
245
|
+
# In that case we ignore this rstring delimiter
|
246
|
+
if next_c:
|
247
|
+
self.index += 1
|
248
|
+
char = self.get_char_at()
|
243
249
|
|
244
250
|
if char and fixed_quotes and self.context == "object_key" and char.isspace():
|
245
251
|
self.skip_whitespaces_at()
|
@@ -253,10 +259,8 @@ class JSONParser:
|
|
253
259
|
self.insert_char_at(rstring_delimiter)
|
254
260
|
else:
|
255
261
|
self.index += 1
|
256
|
-
if double_delimiter and self.get_char_at() == rstring_delimiter:
|
257
|
-
self.index += 1
|
258
262
|
|
259
|
-
return self.json_str[start:end]
|
263
|
+
return self.json_str[start:end].rstrip()
|
260
264
|
|
261
265
|
def parse_number(self) -> Union[float, int, str]:
|
262
266
|
# <number> is a valid real number expressed in one of a number of given formats
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.14.0
|
4
4
|
Summary: A package to repair broken json strings
|
5
5
|
Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
|
6
6
|
License: MIT License
|
@@ -150,7 +150,10 @@ You will need owner access to this repository
|
|
150
150
|
- Run `python -m build`
|
151
151
|
- Create a new release in Github, making sure to tag all the issues solved and contributors. Create the new tag, same as the one in the build configuration
|
152
152
|
- Once the release is created, a new Github Actions workflow will start to publish on Pypi, make sure it didn't fail
|
153
|
-
|
153
|
+
---
|
154
|
+
# Repair JSON in other programming languages
|
155
|
+
- Typescript: https://github.com/josdejong/jsonrepair
|
156
|
+
- Go: https://github.com/RealAlexandreAI/json-repair
|
154
157
|
---
|
155
158
|
# Bonus Content
|
156
159
|
If you need some good Custom Instructions (System Message) to improve your chatbot responses try https://gist.github.com/mangiucugna/7ec015c4266df11be8aa510be0110fe4
|
@@ -0,0 +1,7 @@
|
|
1
|
+
json_repair/__init__.py,sha256=AlNie5y6BZBioGi5fzTAUvum_y0U5aL5aNsuQ_68LQc,175
|
2
|
+
json_repair/json_repair.py,sha256=8B5HfWoLlUUtRYq1cnbajOxWiMSD9nxNW2cRFPjFfVE,15817
|
3
|
+
json_repair-0.14.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
+
json_repair-0.14.0.dist-info/METADATA,sha256=82KldmuVFLXbNy6SXar9MsulkcBUM1K8RX13pNysHQU,7355
|
5
|
+
json_repair-0.14.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
json_repair-0.14.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
+
json_repair-0.14.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=DB220fZ1BCf--9CeP6AzL2FCk9tpE1Eh3WxgFo33P88,15460
|
3
|
-
json_repair-0.13.1.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
-
json_repair-0.13.1.dist-info/METADATA,sha256=gcfdAU5nhvlHlE3wMvGcwHRQUzgPT2p08cgDg7iyLvw,7200
|
5
|
-
json_repair-0.13.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
json_repair-0.13.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
-
json_repair-0.13.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|