json-repair 0.47.0__py3-none-any.whl → 0.47.2__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.
@@ -97,13 +97,6 @@ class JSONParser:
97
97
  elif char == "[":
98
98
  self.index += 1
99
99
  return self.parse_array()
100
- # there can be an edge case in which a key is empty and at the end of an object
101
- # like "key": }. We return an empty string here to close the object properly
102
- elif self.context.current == ContextValues.OBJECT_VALUE and char == "}":
103
- self.log(
104
- "At the end of an object we found a key with missing value, skipping",
105
- )
106
- return ""
107
100
  # <string> starts with a quote
108
101
  elif not self.context.empty and (char in self.STRING_DELIMITERS or char.isalpha()):
109
102
  return self.parse_string()
@@ -202,7 +195,15 @@ class JSONParser:
202
195
  self.context.reset()
203
196
  self.context.set(ContextValues.OBJECT_VALUE)
204
197
  # The value can be any valid json
205
- value = self.parse_json()
198
+ self.skip_whitespaces_at()
199
+ # Corner case, a lone comma
200
+ value: JSONReturnType = ""
201
+ if (self.get_char_at() or "") in [",", "}"]:
202
+ self.log(
203
+ "While parsing an object value we found a stray , ignoring it",
204
+ )
205
+ else:
206
+ value = self.parse_json()
206
207
 
207
208
  # Reset context since our job is done
208
209
  self.context.reset()
@@ -37,9 +37,9 @@ def repair_json(
37
37
  skip_json_loads: bool = False,
38
38
  logging: bool = False,
39
39
  json_fd: TextIO | None = None,
40
- ensure_ascii: bool = True,
41
40
  chunk_length: int = 0,
42
41
  stream_stable: bool = False,
42
+ **json_dumps_args,
43
43
  ) -> str: ...
44
44
 
45
45
 
@@ -50,9 +50,9 @@ def repair_json(
50
50
  skip_json_loads: bool = False,
51
51
  logging: bool = False,
52
52
  json_fd: TextIO | None = None,
53
- ensure_ascii: bool = True,
54
53
  chunk_length: int = 0,
55
54
  stream_stable: bool = False,
55
+ **json_dumps_args,
56
56
  ) -> JSONReturnType | tuple[JSONReturnType, list[dict[str, str]]]: ...
57
57
 
58
58
 
@@ -62,9 +62,9 @@ def repair_json(
62
62
  skip_json_loads: bool = False,
63
63
  logging: bool = False,
64
64
  json_fd: TextIO | None = None,
65
- ensure_ascii: bool = True,
66
65
  chunk_length: int = 0,
67
66
  stream_stable: bool = False,
67
+ **json_dumps_args,
68
68
  ) -> JSONReturnType | tuple[JSONReturnType, list[dict[str, str]]]:
69
69
  """
70
70
  Given a json formatted string, it will try to decode it and, if it fails, it will try to fix it.
@@ -96,7 +96,7 @@ def repair_json(
96
96
  # Avoid returning only a pair of quotes if it's an empty string
97
97
  elif parsed_json == "":
98
98
  return ""
99
- return json.dumps(parsed_json, ensure_ascii=ensure_ascii)
99
+ return json.dumps(parsed_json, **json_dumps_args)
100
100
 
101
101
 
102
102
  def loads(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.47.0
3
+ Version: 0.47.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: MIT License
@@ -175,6 +175,10 @@ will return
175
175
 
176
176
  {"test_chinese_ascii": "统一码"}
177
177
 
178
+ ### JSON dumps parameters
179
+
180
+ More in general, `repair_json` will accept all parameters that `json.dumps` accepts and just pass them through (for example indent)
181
+
178
182
  ### Performance considerations
179
183
  If you find this library too slow because is using `json.loads()` you can skip that by passing `skip_json_loads=True` to `repair_json`. Like:
180
184
 
@@ -1,14 +1,14 @@
1
1
  json_repair/__init__.py,sha256=6FDD6dEVM5Pb5o4Zodgw4ex30Hzy-YvNRy0vts9SQ4I,118
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=YBi07AfBGoZ54locsc6j1Y7WfdretFzmt0wXDEWwRo8,40321
5
- json_repair/json_repair.py,sha256=pyH5fCkS1lyNPVjkqXerQ91lBz3eTHDPgV1QtnvJm-Y,11243
4
+ json_repair/json_parser.py,sha256=34ClVO9cJtL_47PIbYe0Uu3Md30LRQcFaZOe2lTTNR4,40219
5
+ json_repair/json_repair.py,sha256=0qL2LuzlNJa3VnEqYNaJyZNAL2w18oAt2YvA-TlMxmY,11211
6
6
  json_repair/object_comparer.py,sha256=LlIF0MisRglzC-CiG5AxAEDCBWBHeJd-6uXYx0uRmCk,1175
7
7
  json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  json_repair/string_file_wrapper.py,sha256=tGkWBEUPE-CZPf4uSM5NE9oSDTpskX0myJiXsl-gbds,4333
9
- json_repair-0.47.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
10
- json_repair-0.47.0.dist-info/METADATA,sha256=HDyogQyOe0FUVMSnZ-_wm9HlOzXWkRyp4zjQPgZCfMU,12208
11
- json_repair-0.47.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- json_repair-0.47.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
13
- json_repair-0.47.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
14
- json_repair-0.47.0.dist-info/RECORD,,
9
+ json_repair-0.47.2.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
10
+ json_repair-0.47.2.dist-info/METADATA,sha256=jcY7RmAHk6yS1C68gsbZS26xZndDJzeo9ZudgI5JABM,12368
11
+ json_repair-0.47.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ json_repair-0.47.2.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
13
+ json_repair-0.47.2.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
14
+ json_repair-0.47.2.dist-info/RECORD,,