json-repair 0.45.1__py3-none-any.whl → 0.46.1__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 +18 -2
- json_repair/object_comparer.py +1 -1
- {json_repair-0.45.1.dist-info → json_repair-0.46.1.dist-info}/METADATA +3 -2
- {json_repair-0.45.1.dist-info → json_repair-0.46.1.dist-info}/RECORD +8 -8
- {json_repair-0.45.1.dist-info → json_repair-0.46.1.dist-info}/WHEEL +1 -1
- {json_repair-0.45.1.dist-info → json_repair-0.46.1.dist-info}/entry_points.txt +0 -0
- {json_repair-0.45.1.dist-info → json_repair-0.46.1.dist-info}/licenses/LICENSE +0 -0
- {json_repair-0.45.1.dist-info → json_repair-0.46.1.dist-info}/top_level.txt +0 -0
json_repair/json_parser.py
CHANGED
@@ -41,7 +41,7 @@ class JSONParser:
|
|
41
41
|
self.log = self._log
|
42
42
|
else:
|
43
43
|
# No-op
|
44
|
-
self.log = lambda *args, **kwargs: None
|
44
|
+
self.log = lambda *args, **kwargs: None # noqa: ARG005
|
45
45
|
# When the json to be repaired is the accumulation of streaming json at a certain moment.
|
46
46
|
# e.g. json obtained from llm response.
|
47
47
|
# If this parameter to True will keep the repair results stable. For example:
|
@@ -67,6 +67,9 @@ class JSONParser:
|
|
67
67
|
# replace the last entry with the new one since the new one seems an update
|
68
68
|
json.pop()
|
69
69
|
json.append(j)
|
70
|
+
else:
|
71
|
+
# this was a bust, move the index
|
72
|
+
self.index += 1
|
70
73
|
# If nothing extra was found, don't return an array
|
71
74
|
if len(json) == 1:
|
72
75
|
self.log(
|
@@ -231,7 +234,20 @@ class JSONParser:
|
|
231
234
|
char = self.get_char_at()
|
232
235
|
while char and char not in ["]", "}"]:
|
233
236
|
self.skip_whitespaces_at()
|
234
|
-
value =
|
237
|
+
value: JSONReturnType = ""
|
238
|
+
if char in self.STRING_DELIMITERS:
|
239
|
+
# Sometimes it can happen that LLMs forget to start an object and then you think it's a string in an array
|
240
|
+
# So we are going to check if this string is followed by a : or not
|
241
|
+
# And either parse the string or parse the object
|
242
|
+
i = 1
|
243
|
+
i = self.skip_to_character(char, i)
|
244
|
+
i = self.skip_whitespaces_at(idx=i + 1, move_main_index=False)
|
245
|
+
if self.get_char_at(i) == ":":
|
246
|
+
value = self.parse_object()
|
247
|
+
else:
|
248
|
+
value = self.parse_string()
|
249
|
+
else:
|
250
|
+
value = self.parse_json()
|
235
251
|
|
236
252
|
# It is possible that parse_json() returns nothing valid, so we increase by 1
|
237
253
|
if value == "":
|
json_repair/object_comparer.py
CHANGED
@@ -6,7 +6,7 @@ class ObjectComparer: # pragma: no cover
|
|
6
6
|
pass # No operation performed in the constructor
|
7
7
|
|
8
8
|
@staticmethod
|
9
|
-
def is_same_object(obj1: Any, obj2: Any
|
9
|
+
def is_same_object(obj1: Any, obj2: Any) -> bool:
|
10
10
|
"""
|
11
11
|
Recursively compares two objects and ensures that:
|
12
12
|
- Their types match
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.46.1
|
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
|
@@ -38,7 +38,7 @@ License-File: LICENSE
|
|
38
38
|
Dynamic: license-file
|
39
39
|
|
40
40
|
[](https://pypi.org/project/json-repair/)
|
41
|
-

|
42
42
|
[](https://pypi.org/project/json-repair/)
|
43
43
|
[](https://github.com/sponsors/mangiucugna)
|
44
44
|
[](https://github.com/mangiucugna/json_repair/stargazers)
|
@@ -289,6 +289,7 @@ You will need owner access to this repository
|
|
289
289
|
- Typescript: https://github.com/josdejong/jsonrepair
|
290
290
|
- Go: https://github.com/RealAlexandreAI/json-repair
|
291
291
|
- Ruby: https://github.com/sashazykov/json-repair-rb
|
292
|
+
- Rust: https://github.com/oramasearch/llm_json
|
292
293
|
---
|
293
294
|
## Star History
|
294
295
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
json_repair/__init__.py,sha256=c4L2kZrHvWEKfj_ODU2naliNuvU6FlFVxtF0hbLe6s8,178
|
2
2
|
json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
|
3
3
|
json_repair/json_context.py,sha256=WsMOjqpGSr6aaDONcrk8UFtTurzWon2Qq9AoBBYseoI,934
|
4
|
-
json_repair/json_parser.py,sha256=
|
4
|
+
json_repair/json_parser.py,sha256=7IPu-tin9jLX_y1F9tn3UVpqILARhZYFaTTvq9xrLnU,40451
|
5
5
|
json_repair/json_repair.py,sha256=9wxf0vVNfr_RNQI1rbVPvxQ9feEwwvgnvkiYXwGEBX8,11292
|
6
|
-
json_repair/object_comparer.py,sha256=
|
6
|
+
json_repair/object_comparer.py,sha256=5-LK-s_2MAHddTxqXSzSkaIFvPXKGLh6swC1gyN74Lk,1245
|
7
7
|
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
json_repair/string_file_wrapper.py,sha256=uwW4B1s9Cf-iF3ANsCz-RPu2ddCqDETrt8bdojh8ufA,4485
|
9
|
-
json_repair-0.
|
10
|
-
json_repair-0.
|
11
|
-
json_repair-0.
|
12
|
-
json_repair-0.
|
13
|
-
json_repair-0.
|
14
|
-
json_repair-0.
|
9
|
+
json_repair-0.46.1.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
10
|
+
json_repair-0.46.1.dist-info/METADATA,sha256=y-p_aOKtX4eu7p-JNj6IO3s8svB06IityZRnRKEN_xE,12208
|
11
|
+
json_repair-0.46.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
12
|
+
json_repair-0.46.1.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
13
|
+
json_repair-0.46.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
14
|
+
json_repair-0.46.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|