json-repair 0.48.0__py3-none-any.whl → 0.49.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.
@@ -169,6 +169,9 @@ class JSONParser:
169
169
  char = self.json_str[self.index + idx]
170
170
  except IndexError:
171
171
  return idx
172
+ if self.json_str[self.index + idx - 1] == "\\":
173
+ # Ah shoot this was actually escaped, continue
174
+ return self.skip_to_character(character, idx + 1)
172
175
  return idx
173
176
 
174
177
  def _log(self, text: str) -> None:
@@ -66,7 +66,7 @@ def repair_json(
66
66
  chunk_length: int = 0,
67
67
  stream_stable: bool = False,
68
68
  **json_dumps_args,
69
- ) -> JSONReturnType | tuple[JSONReturnType, list[dict[str, str]]]:
69
+ ) -> JSONReturnType | tuple[JSONReturnType, list[dict[str, str]]] | tuple[JSONReturnType, list]:
70
70
  """
71
71
  Given a json formatted string, it will try to decode it and, if it fails, it will try to fix it.
72
72
 
@@ -74,13 +74,13 @@ def repair_json(
74
74
  json_str (str, optional): The JSON string to repair. Defaults to an empty string.
75
75
  return_objects (bool, optional): If True, return the decoded data structure. Defaults to False.
76
76
  skip_json_loads (bool, optional): If True, skip calling the built-in json.loads() function to verify that the json is valid before attempting to repair. Defaults to False.
77
- logging (bool, optional): If True, return a tuple with the repaired json and a log of all repair actions. Defaults to False.
77
+ logging (bool, optional): If True, return a tuple with the repaired json and a log of all repair actions. Defaults to False. When no repairs were required, the repair log will be an empty list.
78
78
  json_fd (Optional[TextIO], optional): File descriptor for JSON input. Do not use! Use `from_file` or `load` instead. Defaults to None.
79
79
  ensure_ascii (bool, optional): Set to False to avoid converting non-latin characters to ascii (for example when using chinese characters). Defaults to True. Ignored if `skip_json_loads` is True.
80
80
  chunk_length (int, optional): Size in bytes of the file chunks to read at once. Ignored if `json_fd` is None. Do not use! Use `from_file` or `load` instead. Defaults to 1MB.
81
81
  stream_stable (bool, optional): When the json to be repaired is the accumulation of streaming json at a certain moment.If this parameter to True will keep the repair results stable.
82
82
  Returns:
83
- Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]: The repaired JSON or a tuple with the repaired JSON and repair log.
83
+ Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]: The repaired JSON or a tuple with the repaired JSON and repair log when logging is True.
84
84
  """
85
85
  parser = JSONParser(json_str, json_fd, logging, chunk_length, stream_stable)
86
86
  if skip_json_loads:
@@ -93,6 +93,10 @@ def repair_json(
93
93
  # It's useful to return the actual object instead of the json string,
94
94
  # it allows this lib to be a replacement of the json library
95
95
  if return_objects or logging:
96
+ # If logging is True, the user should expect a tuple.
97
+ # If json.load(s) worked, the repair log list is empty
98
+ if logging and not isinstance(parsed_json, tuple):
99
+ return parsed_json, []
96
100
  return parsed_json
97
101
  # Avoid returning only a pair of quotes if it's an empty string
98
102
  elif parsed_json == "":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.48.0
3
+ Version: 0.49.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
@@ -40,6 +40,7 @@ Dynamic: license-file
40
40
  [![PyPI](https://img.shields.io/pypi/v/json-repair)](https://pypi.org/project/json-repair/)
41
41
  ![Python version](https://img.shields.io/badge/python-3.10+-important)
42
42
  [![PyPI downloads](https://img.shields.io/pypi/dm/json-repair)](https://pypi.org/project/json-repair/)
43
+ [![PyPI Downloads](https://static.pepy.tech/badge/json-repair)](https://pepy.tech/projects/json-repair)
43
44
  [![Github Sponsors](https://img.shields.io/github/sponsors/mangiucugna)](https://github.com/sponsors/mangiucugna)
44
45
  [![GitHub Repo stars](https://img.shields.io/github/stars/mangiucugna/json_repair?style=flat)](https://github.com/mangiucugna/json_repair/stargazers)
45
46
 
@@ -2,8 +2,8 @@ json_repair/__init__.py,sha256=JdJIZNCKV3MfIviryqK8NH8yGssCta2-192CekcwH-o,174
2
2
  json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
3
3
  json_repair/constants.py,sha256=cv2gvyosuq0me0600WyTysM9avrtfXPuXYR26tawcuo,158
4
4
  json_repair/json_context.py,sha256=WsMOjqpGSr6aaDONcrk8UFtTurzWon2Qq9AoBBYseoI,934
5
- json_repair/json_parser.py,sha256=rTuL8ESslQ4XK9fkLmBIpS4e8xr6QwlZRVyJwzJFqBE,7356
6
- json_repair/json_repair.py,sha256=txblCJtcTpXcQaT15tavulkJPtyRYe2cfYpPHZcvPv0,11233
5
+ json_repair/json_parser.py,sha256=BgppUAmxpVhIpwzXYn5LxvtSukx5HWjxoBJU7gKgmRY,7533
6
+ json_repair/json_repair.py,sha256=sDhXzDZxu0QmaFzICPTtf_q7yOY1A1Lf_iQG6Potsco,11572
7
7
  json_repair/object_comparer.py,sha256=XKV3MRab8H7_v4sm-wpEa5le0XX9OeycWo5S-MFm-GI,1716
8
8
  json_repair/parse_array.py,sha256=-rh65JcfT-FtXiR6s8RYlMfI-6LzVr08ytlDh6Z2CFE,2181
9
9
  json_repair/parse_boolean_or_null.py,sha256=WMSkvvxsp4wvauBcDqtt9WnLMD5SMoxeRfZFXp3FEBc,890
@@ -13,9 +13,9 @@ json_repair/parse_object.py,sha256=UzkY0C5NSE2CtVnZwugMyhhtUJPgs0MwBb4kF4l2ftU,4
13
13
  json_repair/parse_string.py,sha256=Ju1txvEWrOQnncigBOnlkEdVwXYGz4jaKr9QOpjAx5o,22947
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.48.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
17
- json_repair-0.48.0.dist-info/METADATA,sha256=--ltEVHVgM9Jh9wxa--Ad22rM34kXNO5faj1oHtBIO8,12411
18
- json_repair-0.48.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- json_repair-0.48.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
20
- json_repair-0.48.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
21
- json_repair-0.48.0.dist-info/RECORD,,
16
+ json_repair-0.49.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
17
+ json_repair-0.49.0.dist-info/METADATA,sha256=KVQrd4CeKrlIq4XBLrnzoNi2SbbgG1kig4eK3Qs2r18,12515
18
+ json_repair-0.49.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ json_repair-0.49.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
20
+ json_repair-0.49.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
21
+ json_repair-0.49.0.dist-info/RECORD,,