json-repair 0.49.0__py3-none-any.whl → 0.50.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_parser.py +3 -2
- json_repair/parse_string.py +35 -15
- {json_repair-0.49.0.dist-info → json_repair-0.50.0.dist-info}/METADATA +3 -30
- {json_repair-0.49.0.dist-info → json_repair-0.50.0.dist-info}/RECORD +8 -8
- {json_repair-0.49.0.dist-info → json_repair-0.50.0.dist-info}/WHEEL +0 -0
- {json_repair-0.49.0.dist-info → json_repair-0.50.0.dist-info}/entry_points.txt +0 -0
- {json_repair-0.49.0.dist-info → json_repair-0.50.0.dist-info}/licenses/LICENSE +0 -0
- {json_repair-0.49.0.dist-info → json_repair-0.50.0.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, idx: int = 0) -> int:
|
158
|
+
def skip_to_character(self, character: str | list, 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
|
"""
|
@@ -163,7 +163,8 @@ class JSONParser:
|
|
163
163
|
char = self.json_str[self.index + idx]
|
164
164
|
except IndexError:
|
165
165
|
return idx
|
166
|
-
|
166
|
+
character_list = character if isinstance(character, list) else [character]
|
167
|
+
while char not in character_list:
|
167
168
|
idx += 1
|
168
169
|
try:
|
169
170
|
char = self.json_str[self.index + idx]
|
json_repair/parse_string.py
CHANGED
@@ -104,11 +104,17 @@ def parse_string(self: "JSONParser") -> str | bool | None:
|
|
104
104
|
char = self.get_char_at()
|
105
105
|
unmatched_delimiter = False
|
106
106
|
while char and char != rstring_delimiter:
|
107
|
-
if missing_quotes
|
108
|
-
self.
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
if missing_quotes:
|
108
|
+
if self.context.current == ContextValues.OBJECT_KEY and (char == ":" or char.isspace()):
|
109
|
+
self.log(
|
110
|
+
"While parsing a string missing the left delimiter in object key context, we found a :, stopping here",
|
111
|
+
)
|
112
|
+
break
|
113
|
+
elif self.context.current == ContextValues.ARRAY and char in ["]", ","]:
|
114
|
+
self.log(
|
115
|
+
"While parsing a string missing the left delimiter in array context, we found a ] or ,, stopping here",
|
116
|
+
)
|
117
|
+
break
|
112
118
|
if (
|
113
119
|
not self.stream_stable
|
114
120
|
and self.context.current == ContextValues.OBJECT_VALUE
|
@@ -385,16 +391,30 @@ def parse_string(self: "JSONParser") -> str | bool | None:
|
|
385
391
|
self.index += 1
|
386
392
|
char = self.get_char_at()
|
387
393
|
elif self.context.current == ContextValues.ARRAY:
|
388
|
-
#
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
self.
|
397
|
-
|
394
|
+
# Let's check if after this quote there are two quotes in a row followed by a comma or a closing bracket
|
395
|
+
i = self.skip_to_character(character=[rstring_delimiter, "]"], idx=i + 1)
|
396
|
+
next_c = self.get_char_at(i)
|
397
|
+
even_delimiters = next_c and next_c == rstring_delimiter
|
398
|
+
while even_delimiters and next_c and next_c == rstring_delimiter:
|
399
|
+
i = self.skip_to_character(character=[rstring_delimiter, "]"], idx=i + 1)
|
400
|
+
i = self.skip_to_character(character=[rstring_delimiter, "]"], idx=i + 1)
|
401
|
+
next_c = self.get_char_at(i)
|
402
|
+
# i = self.skip_whitespaces_at(idx=i + 1, move_main_index=False)
|
403
|
+
# next_c = self.get_char_at(i)
|
404
|
+
# if next_c in [",", "]"]:
|
405
|
+
if even_delimiters and next_c != "]":
|
406
|
+
# If we got up to here it means that this is a situation like this:
|
407
|
+
# ["bla bla bla "puppy" bla bla bla "kitty" bla bla"]
|
408
|
+
# So we need to ignore this quote
|
409
|
+
self.log(
|
410
|
+
"While parsing a string in Array context, we detected a quoted section that would have closed the string but has a different meaning here, ignoring it",
|
411
|
+
)
|
412
|
+
unmatched_delimiter = not unmatched_delimiter
|
413
|
+
string_acc += str(char)
|
414
|
+
self.index += 1
|
415
|
+
char = self.get_char_at()
|
416
|
+
else:
|
417
|
+
break
|
398
418
|
elif self.context.current == ContextValues.OBJECT_KEY:
|
399
419
|
# In this case we just ignore this and move on
|
400
420
|
self.log(
|
@@ -1,36 +1,14 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.50.0
|
4
4
|
Summary: A package to repair broken json strings
|
5
5
|
Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
|
6
|
-
License: MIT
|
7
|
-
|
8
|
-
Copyright (c) 2023 Stefano Baccianella
|
9
|
-
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
12
|
-
in the Software without restriction, including without limitation the rights
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
15
|
-
furnished to do so, subject to the following conditions:
|
16
|
-
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
18
|
-
copies or substantial portions of the Software.
|
19
|
-
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
-
SOFTWARE.
|
27
|
-
|
6
|
+
License-Expression: MIT
|
28
7
|
Project-URL: Homepage, https://github.com/mangiucugna/json_repair/
|
29
8
|
Project-URL: Bug Tracker, https://github.com/mangiucugna/json_repair/issues
|
30
9
|
Project-URL: Live demo, https://mangiucugna.github.io/json_repair/
|
31
10
|
Keywords: JSON,REPAIR,LLM,PARSER
|
32
11
|
Classifier: Programming Language :: Python :: 3
|
33
|
-
Classifier: License :: OSI Approved :: MIT License
|
34
12
|
Classifier: Operating System :: OS Independent
|
35
13
|
Requires-Python: >=3.10
|
36
14
|
Description-Content-Type: text/markdown
|
@@ -39,7 +17,7 @@ Dynamic: license-file
|
|
39
17
|
|
40
18
|
[](https://pypi.org/project/json-repair/)
|
41
19
|

|
42
|
-
[](https://pepy.tech/projects/json-repair)
|
43
21
|
[](https://pepy.tech/projects/json-repair)
|
44
22
|
[](https://github.com/sponsors/mangiucugna)
|
45
23
|
[](https://github.com/mangiucugna/json_repair/stargazers)
|
@@ -70,11 +48,6 @@ I searched for a lightweight python package that was able to reliably fix this p
|
|
70
48
|
|
71
49
|
*So I wrote one*
|
72
50
|
|
73
|
-
### Wouldn't GPT-4o Structured Output make this library outdated?
|
74
|
-
|
75
|
-
As part of my job we use OpenAI APIs and we noticed that even with structured output sometimes the result isn't a fully valid json.
|
76
|
-
So we still use this library to cover those outliers.
|
77
|
-
|
78
51
|
# Supported use cases
|
79
52
|
|
80
53
|
### Fixing Syntax Errors in JSON
|
@@ -2,7 +2,7 @@ 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=glod61Zc6HtVxwvGxBwbz8WEU0BB5LkNZXLw4Z956yI,7632
|
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
|
@@ -10,12 +10,12 @@ json_repair/parse_boolean_or_null.py,sha256=WMSkvvxsp4wvauBcDqtt9WnLMD5SMoxeRfZF
|
|
10
10
|
json_repair/parse_comment.py,sha256=JHtQ_QlxOvPNnMh7lhUaoTjFGelqjhTNq7qn9xUE7SU,2648
|
11
11
|
json_repair/parse_number.py,sha256=33zAtkbuVzi9Lqjxu7cXn9WlVzd3WjRx9Ln_LFzVL4o,1259
|
12
12
|
json_repair/parse_object.py,sha256=UzkY0C5NSE2CtVnZwugMyhhtUJPgs0MwBb4kF4l2ftU,4563
|
13
|
-
json_repair/parse_string.py,sha256=
|
13
|
+
json_repair/parse_string.py,sha256=FTTlgfjXcR2N4Et_f2qBhqXvfEps_L0oznp_ORup1_A,24323
|
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.50.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
17
|
+
json_repair-0.50.0.dist-info/METADATA,sha256=_90s7Q5c2SSf--pfiykcfjLXdDZqBTjGU269JXj1uPI,10987
|
18
|
+
json_repair-0.50.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
19
|
+
json_repair-0.50.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
20
|
+
json_repair-0.50.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
21
|
+
json_repair-0.50.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|