json-repair 0.45.0__py3-none-any.whl → 0.46.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.
@@ -231,7 +231,20 @@ class JSONParser:
231
231
  char = self.get_char_at()
232
232
  while char and char not in ["]", "}"]:
233
233
  self.skip_whitespaces_at()
234
- value = self.parse_json()
234
+ value: JSONReturnType = ""
235
+ if char in self.STRING_DELIMITERS:
236
+ # Sometimes it can happen that LLMs forget to start an object and then you think it's a string in an array
237
+ # So we are going to check if this string is followed by a : or not
238
+ # And either parse the string or parse the object
239
+ i = 1
240
+ i = self.skip_to_character(char, i)
241
+ i = self.skip_whitespaces_at(idx=i + 1, move_main_index=False)
242
+ if self.get_char_at(i) == ":":
243
+ value = self.parse_object()
244
+ else:
245
+ value = self.parse_string()
246
+ else:
247
+ value = self.parse_json()
235
248
 
236
249
  # It is possible that parse_json() returns nothing valid, so we increase by 1
237
250
  if value == "":
@@ -790,6 +803,11 @@ class JSONParser:
790
803
  break
791
804
  self.log(f"Found block comment: {comment}")
792
805
  return ""
806
+ else:
807
+ # Skip standalone '/' characters that are not part of a comment
808
+ # to avoid getting stuck in an infinite loop
809
+ self.index += 1
810
+ return ""
793
811
  return "" # pragma: no cover
794
812
 
795
813
  def get_char_at(self, count: int = 0) -> str | Literal[False]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.45.0
3
+ Version: 0.46.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
@@ -32,7 +32,7 @@ Keywords: JSON,REPAIR,LLM,PARSER
32
32
  Classifier: Programming Language :: Python :: 3
33
33
  Classifier: License :: OSI Approved :: MIT License
34
34
  Classifier: Operating System :: OS Independent
35
- Requires-Python: >=3.9
35
+ Requires-Python: >=3.10
36
36
  Description-Content-Type: text/markdown
37
37
  License-File: LICENSE
38
38
  Dynamic: license-file
@@ -103,6 +103,7 @@ then you can use use it in your code like this
103
103
  good_json_string = repair_json(bad_json_string)
104
104
  # If the string was super broken this will return an empty string
105
105
 
106
+
106
107
  You can use this library to completely replace `json.loads()`:
107
108
 
108
109
  import json_repair
@@ -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=DnLeC0SKTs9yaixYBYZ3J4gwxGXwOLsTWHelptGUp4Q,39407
4
+ json_repair/json_parser.py,sha256=y-JZiKUjC5IdB2u4OR2SyDQcOWO2EIJz1iRKHlLRXYo,40323
5
5
  json_repair/json_repair.py,sha256=9wxf0vVNfr_RNQI1rbVPvxQ9feEwwvgnvkiYXwGEBX8,11292
6
6
  json_repair/object_comparer.py,sha256=ZjxrzepSNGrhiwzid2Dm657x1Aj-E1-h37bDygK8ByE,1261
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.45.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
10
- json_repair-0.45.0.dist-info/METADATA,sha256=0RAn-AntRZtUdgJcBt8tvsZG-hHadaGfB9Vy2PBRcRk,12157
11
- json_repair-0.45.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
12
- json_repair-0.45.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
13
- json_repair-0.45.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
14
- json_repair-0.45.0.dist-info/RECORD,,
9
+ json_repair-0.46.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
10
+ json_repair-0.46.0.dist-info/METADATA,sha256=xp8t58AzqrRymn8hBe0KSjcM92Auek4vj56dzCdDSM8,12159
11
+ json_repair-0.46.0.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
12
+ json_repair-0.46.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
13
+ json_repair-0.46.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
14
+ json_repair-0.46.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.7.1)
2
+ Generator: setuptools (80.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5