json-repair 0.52.0__tar.gz → 0.52.2__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 (35) hide show
  1. {json_repair-0.52.0/src/json_repair.egg-info → json_repair-0.52.2}/PKG-INFO +1 -1
  2. {json_repair-0.52.0 → json_repair-0.52.2}/pyproject.toml +1 -1
  3. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/json_parser.py +1 -1
  4. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/parse_string.py +23 -2
  5. {json_repair-0.52.0 → json_repair-0.52.2/src/json_repair.egg-info}/PKG-INFO +1 -1
  6. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_parse_object.py +2 -0
  7. {json_repair-0.52.0 → json_repair-0.52.2}/LICENSE +0 -0
  8. {json_repair-0.52.0 → json_repair-0.52.2}/README.md +0 -0
  9. {json_repair-0.52.0 → json_repair-0.52.2}/setup.cfg +0 -0
  10. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/__init__.py +0 -0
  11. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/__main__.py +0 -0
  12. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/constants.py +0 -0
  13. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/json_context.py +0 -0
  14. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/json_repair.py +0 -0
  15. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/object_comparer.py +0 -0
  16. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/parse_array.py +0 -0
  17. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/parse_boolean_or_null.py +0 -0
  18. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/parse_comment.py +0 -0
  19. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/parse_number.py +0 -0
  20. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/parse_object.py +0 -0
  21. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/py.typed +0 -0
  22. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair/string_file_wrapper.py +0 -0
  23. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair.egg-info/SOURCES.txt +0 -0
  24. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair.egg-info/dependency_links.txt +0 -0
  25. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair.egg-info/entry_points.txt +0 -0
  26. {json_repair-0.52.0 → json_repair-0.52.2}/src/json_repair.egg-info/top_level.txt +0 -0
  27. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_json_repair.py +0 -0
  28. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_parse_array.py +0 -0
  29. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_parse_boolean_or_null.py +0 -0
  30. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_parse_comment.py +0 -0
  31. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_parse_number.py +0 -0
  32. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_parse_string.py +0 -0
  33. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_performance.py +0 -0
  34. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_repair_json_cli.py +0 -0
  35. {json_repair-0.52.0 → json_repair-0.52.2}/tests/test_repair_json_from_file.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.52.0
3
+ Version: 0.52.2
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-Expression: MIT
@@ -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.52.0"
6
+ version = "0.52.2"
7
7
  license = "MIT"
8
8
  license-files = ["LICENSE"]
9
9
  authors = [
@@ -155,7 +155,7 @@ class JSONParser:
155
155
  return idx
156
156
  return idx
157
157
 
158
- def skip_to_character(self, character: str | list, idx: int = 0) -> int:
158
+ def skip_to_character(self, character: str | list[str], 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
  """
@@ -1,13 +1,13 @@
1
1
  from typing import TYPE_CHECKING
2
2
 
3
- from .constants import STRING_DELIMITERS
3
+ from .constants import STRING_DELIMITERS, JSONReturnType
4
4
  from .json_context import ContextValues
5
5
 
6
6
  if TYPE_CHECKING:
7
7
  from .json_parser import JSONParser
8
8
 
9
9
 
10
- def parse_string(self: "JSONParser") -> str | bool | None:
10
+ def parse_string(self: "JSONParser") -> JSONReturnType:
11
11
  # <string> is a string of valid characters enclosed in quotes
12
12
  # i.e. { name: "John" }
13
13
  # Somehow all weird cases in an invalid JSON happen to be resolved in this function, so be careful here
@@ -201,6 +201,27 @@ def parse_string(self: "JSONParser") -> str | bool | None:
201
201
  if not self.get_char_at(i):
202
202
  # No delimiter found
203
203
  break
204
+ if self.context.current == ContextValues.OBJECT_VALUE and char == "}":
205
+ # We found the end of an object while parsing a value
206
+ # Check if the object is really over, to avoid doubling the closing brace
207
+ i = self.skip_whitespaces_at(idx=1, move_main_index=False)
208
+ next_c = self.get_char_at(i)
209
+ if next_c and next_c == "`":
210
+ # This could be a special case in which the LLM added code fences after the object
211
+ # So we need to check if there are another two ` after this one`
212
+ next_c = self.get_char_at(i + 1)
213
+ if next_c and next_c == "`":
214
+ next_c = self.get_char_at(i + 2)
215
+ if next_c and next_c == "`":
216
+ self.log(
217
+ "While parsing a string in object value context, we found a } that closes the object before code fences, stopping here",
218
+ )
219
+ break
220
+ if not next_c:
221
+ self.log(
222
+ "While parsing a string in object value context, we found a } that closes the object, stopping here",
223
+ )
224
+ break
204
225
  string_acc += char
205
226
  self.index += 1
206
227
  char = self.get_char_at()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.52.0
3
+ Version: 0.52.2
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-Expression: MIT
@@ -23,6 +23,7 @@ def test_parse_object():
23
23
  def test_parse_object_edge_cases():
24
24
  assert repair_json("{foo: [}") == '{"foo": []}'
25
25
  assert repair_json('{"": "value"') == '{"": "value"}'
26
+ assert repair_json('{"key": "v"alue"}') == '{"key": "v\\"alue\\""}'
26
27
  assert repair_json('{"value_1": true, COMMENT "value_2": "data"}') == '{"value_1": true, "value_2": "data"}'
27
28
  assert (
28
29
  repair_json('{"value_1": true, SHOULD_NOT_EXIST "value_2": "data" AAAA }')
@@ -62,6 +63,7 @@ def test_parse_object_edge_cases():
62
63
  assert repair_json("{text:words{words in brackets}}") == '{"text": "words{words in brackets}"}'
63
64
  assert repair_json("{text:words{words in brackets}m}") == '{"text": "words{words in brackets}m"}'
64
65
  assert repair_json('{"key": "value, value2"```') == '{"key": "value, value2"}'
66
+ assert repair_json('{"key": "value}```') == '{"key": "value"}'
65
67
  assert repair_json("{key:value,key2:value2}") == '{"key": "value", "key2": "value2"}'
66
68
  assert repair_json('{"key:"value"}') == '{"key": "value"}'
67
69
  assert repair_json('{"key:value}') == '{"key": "value"}'
File without changes
File without changes
File without changes