json-repair 0.52.5__py3-none-any.whl → 0.53.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.
@@ -7,7 +7,7 @@ if TYPE_CHECKING:
7
7
  from .json_parser import JSONParser
8
8
 
9
9
 
10
- def parse_object(self: "JSONParser") -> dict[str, JSONReturnType]:
10
+ def parse_object(self: "JSONParser") -> JSONReturnType:
11
11
  # <object> ::= '{' [ <member> *(', ' <member>) ] '}' ; A sequence of 'members'
12
12
  obj: dict[str, JSONReturnType] = {}
13
13
  start_index = self.index
@@ -2,6 +2,7 @@ from typing import TYPE_CHECKING
2
2
 
3
3
  from .constants import STRING_DELIMITERS, JSONReturnType
4
4
  from .json_context import ContextValues
5
+ from .parse_string_helpers.parse_json_llm_block import parse_json_llm_block
5
6
 
6
7
  if TYPE_CHECKING:
7
8
  from .json_parser import JSONParser
@@ -49,7 +50,14 @@ def parse_string(self: "JSONParser") -> JSONReturnType:
49
50
 
50
51
  if not missing_quotes:
51
52
  self.index += 1
52
-
53
+ if self.get_char_at() == "`":
54
+ ret_val = parse_json_llm_block(self)
55
+ # If we found a valid JSON block, return it, otherwise continue parsing the string
56
+ if ret_val is not False:
57
+ return ret_val
58
+ self.log(
59
+ "While parsing a string, we found code fences but they did not enclose valid JSON, continuing parsing the string",
60
+ )
53
61
  # There is sometimes a weird case of doubled quotes, we manage this also later in the while loop
54
62
  if self.get_char_at() in STRING_DELIMITERS and self.get_char_at() == lstring_delimiter:
55
63
  # If it's an empty key, this was easy
@@ -0,0 +1,19 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ..constants import JSONReturnType # noqa: TID252
4
+
5
+ if TYPE_CHECKING:
6
+ from ..json_parser import JSONParser # noqa: TID252
7
+
8
+
9
+ def parse_json_llm_block(self: "JSONParser") -> JSONReturnType:
10
+ """
11
+ Extracts and normalizes JSON enclosed in ```json ... ``` blocks.
12
+ """
13
+ # Try to find a ```json ... ``` block
14
+ if self.json_str[self.index : self.index + 7] == "```json":
15
+ i = self.skip_to_character("`", idx=7)
16
+ if self.json_str[self.index + i : self.index + i + 3] == "```":
17
+ self.index += 7 # Move past ```json
18
+ return self.parse_json()
19
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.52.5
3
+ Version: 0.53.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-Expression: MIT
@@ -9,13 +9,14 @@ json_repair/parse_array.py,sha256=-rh65JcfT-FtXiR6s8RYlMfI-6LzVr08ytlDh6Z2CFE,21
9
9
  json_repair/parse_boolean_or_null.py,sha256=WMSkvvxsp4wvauBcDqtt9WnLMD5SMoxeRfZFXp3FEBc,890
10
10
  json_repair/parse_comment.py,sha256=JHtQ_QlxOvPNnMh7lhUaoTjFGelqjhTNq7qn9xUE7SU,2648
11
11
  json_repair/parse_number.py,sha256=33zAtkbuVzi9Lqjxu7cXn9WlVzd3WjRx9Ln_LFzVL4o,1259
12
- json_repair/parse_object.py,sha256=xMpO64sYW0JmUtW75BTD0EdPQjY7PYVgu4tHVXrWB6s,5582
13
- json_repair/parse_string.py,sha256=banF0nNbONvO4C_SDQMDuCZO99UIQvKzRVki9xWVpfU,25686
12
+ json_repair/parse_object.py,sha256=rnuH5Oxo98OrXhktF0wrOC1vRb5Th_m819Li1EFJzm4,5571
13
+ json_repair/parse_string.py,sha256=--coxoyH4nxl7osxgs1fIu31IEtB0HHwVbbOewypG4g,26146
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.52.5.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
17
- json_repair-0.52.5.dist-info/METADATA,sha256=KcP9eWpjKssTAXdp8VSyVzzRnCgpGmK6AcdBnlZAT84,11027
18
- json_repair-0.52.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- json_repair-0.52.5.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
20
- json_repair-0.52.5.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
21
- json_repair-0.52.5.dist-info/RECORD,,
16
+ json_repair/parse_string_helpers/parse_json_llm_block.py,sha256=taREF3pwb35kGBGJYbUHkTybATX3GI-SOwOz3yXaEQs,644
17
+ json_repair-0.53.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
18
+ json_repair-0.53.0.dist-info/METADATA,sha256=JvMUVYGDDIzmym7MqbQ6k6PjbnuuskW_myvk0EWp7V8,11027
19
+ json_repair-0.53.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
+ json_repair-0.53.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
21
+ json_repair-0.53.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
22
+ json_repair-0.53.0.dist-info/RECORD,,