json-repair 0.45.0__tar.gz → 0.46.0__tar.gz

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.
Files changed (20) hide show
  1. {json_repair-0.45.0/src/json_repair.egg-info → json_repair-0.46.0}/PKG-INFO +3 -2
  2. {json_repair-0.45.0 → json_repair-0.46.0}/README.md +1 -0
  3. {json_repair-0.45.0 → json_repair-0.46.0}/pyproject.toml +3 -3
  4. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/json_parser.py +19 -1
  5. {json_repair-0.45.0 → json_repair-0.46.0/src/json_repair.egg-info}/PKG-INFO +3 -2
  6. {json_repair-0.45.0 → json_repair-0.46.0}/tests/test_json_repair.py +2 -0
  7. {json_repair-0.45.0 → json_repair-0.46.0}/LICENSE +0 -0
  8. {json_repair-0.45.0 → json_repair-0.46.0}/setup.cfg +0 -0
  9. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/__init__.py +0 -0
  10. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/__main__.py +0 -0
  11. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/json_context.py +0 -0
  12. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/json_repair.py +0 -0
  13. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/object_comparer.py +0 -0
  14. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/py.typed +0 -0
  15. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair/string_file_wrapper.py +0 -0
  16. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair.egg-info/SOURCES.txt +0 -0
  17. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair.egg-info/dependency_links.txt +0 -0
  18. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair.egg-info/entry_points.txt +0 -0
  19. {json_repair-0.45.0 → json_repair-0.46.0}/src/json_repair.egg-info/top_level.txt +0 -0
  20. {json_repair-0.45.0 → json_repair-0.46.0}/tests/test_performance.py +0 -0
@@ -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
@@ -64,6 +64,7 @@ then you can use use it in your code like this
64
64
  good_json_string = repair_json(bad_json_string)
65
65
  # If the string was super broken this will return an empty string
66
66
 
67
+
67
68
  You can use this library to completely replace `json.loads()`:
68
69
 
69
70
  import json_repair
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "json_repair"
6
- version = "0.45.0"
6
+ version = "0.46.0"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -11,7 +11,7 @@ authors = [
11
11
  description = "A package to repair broken json strings"
12
12
  keywords = ["JSON", "REPAIR", "LLM", "PARSER"]
13
13
  readme = "README.md"
14
- requires-python = ">=3.9"
14
+ requires-python = ">=3.10"
15
15
  classifiers = [
16
16
  "Programming Language :: Python :: 3",
17
17
  "License :: OSI Approved :: MIT License",
@@ -101,4 +101,4 @@ line-ending = "auto"
101
101
 
102
102
  [tool.ruff.lint.per-file-ignores]
103
103
  # Explicit re-exports is fine in __init__.py, still a code smell elsewhere.
104
- "__init__.py" = ["PLC0414"]
104
+ "__init__.py" = ["PLC0414"]
@@ -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
@@ -83,6 +83,7 @@ def test_general_edge_cases():
83
83
  assert repair_json("[[1\n\n]") == "[[1]]"
84
84
  assert repair_json("string") == ""
85
85
  assert repair_json("stringbeforeobject {}") == "{}"
86
+ assert repair_json("/") == ""
86
87
 
87
88
 
88
89
  def test_mixed_data_types():
@@ -192,6 +193,7 @@ def test_array_edge_cases():
192
193
  == '{"key": ["lorem \\"ipsum\\" dolor \\"sit\\" amet, \\"consectetur\\" ", "lorem \\"ipsum\\" dolor", "lorem"]}'
193
194
  )
194
195
  assert repair_json('{"k"e"y": "value"}') == '{"k\\"e\\"y": "value"}'
196
+ assert repair_json('["key":"value"}]') == '[{"key": "value"}]'
195
197
 
196
198
 
197
199
  def test_escaping():
File without changes
File without changes