json-repair 0.15.2__tar.gz → 0.15.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.15.2
3
+ Version: 0.15.4
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
@@ -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.15.2"
6
+ version = "0.15.4"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -78,7 +78,7 @@ class JSONParser:
78
78
  elif char == "“":
79
79
  return self.parse_string(string_quotes=["“", "”"])
80
80
  # <number> starts with [0-9] or minus
81
- elif char.isdigit() or char == "-":
81
+ elif char.isdigit() or char == "-" or char == ".":
82
82
  return self.parse_number()
83
83
  # <boolean> could be (T)rue or (F)alse or (N)ull
84
84
  elif char.lower() in ["t", "f", "n"]:
@@ -226,10 +226,18 @@ class JSONParser:
226
226
  lstring_delimiter = rstring_delimiter = string_quotes
227
227
  # There is sometimes a weird case of doubled quotes, we manage this also later in the while loop
228
228
  if self.get_char_at(1) == lstring_delimiter:
229
- self.log(
230
- "While parsing a string, we found a doubled quote, ignoring it", "info"
231
- )
232
- self.index += 1
229
+ next_next_char = self.get_char_at(2) or ""
230
+ if not next_next_char.isspace() and next_next_char not in [
231
+ ",",
232
+ ":",
233
+ "]",
234
+ "}",
235
+ ]:
236
+ self.log(
237
+ "While parsing a string, we found a doubled quote, ignoring it",
238
+ "info",
239
+ )
240
+ self.index += 1
233
241
  char = self.get_char_at()
234
242
  if char != lstring_delimiter:
235
243
  self.log(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.15.2
3
+ Version: 0.15.4
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
@@ -108,9 +108,11 @@ def test_repair_json():
108
108
  assert repair_json('{"key\t\_": "value"}') == '{"key\\t_": "value"}'
109
109
  assert repair_json('{""answer"":[{""traits"":''Female aged 60+'',""answer1"":""5""}]}') == '{"answer": [{"traits": "Female aged 60+", "answer1": "5"}]}'
110
110
  assert repair_json('{""answer":[{""traits":""Female aged 60+",""answer1":""5"}]}') == '{"answer": [{"traits": "Female aged 60+", "answer1": "5"}]}'
111
- assert repair_json('{"key":"",}') == '{"key": ",}"}'
111
+ assert repair_json('{"key":""') == '{"key": ""}'
112
112
  assert repair_json('{ "words": abcdef", "numbers": 12345", "words2": ghijkl" }') == '{"words": "abcdef", "numbers": 12345, "words2": "ghijkl"}'
113
113
  assert repair_json('{"key": 1/3}') == '{"key": "1/3"}'
114
+ assert repair_json('{"key": .25}') == '{"key": 0.25}'
115
+ assert repair_json("""{ "a": "", "b": [ { "c": 1} ] \n}```""") == '{"a": "", "b": [{"c": 1}]}'
114
116
 
115
117
 
116
118
  def test_repair_json_with_objects():
@@ -256,12 +258,14 @@ def test_repair_json_corner_cases_generate_by_gpt_with_objects():
256
258
  assert repair_json('{"key": 10-20}', True) == {"key": "10-20"}
257
259
  assert repair_json('{"key": 1.1.1}', True) == {"key": "1.1.1"}
258
260
 
261
+
259
262
  def test_repair_json_skip_json_loads():
260
263
  assert repair_json('{"key": true, "key2": false, "key3": null}', skip_json_loads=True) == '{"key": true, "key2": false, "key3": null}'
261
264
  assert repair_json('{"key": true, "key2": false, "key3": null}', return_objects=True, skip_json_loads=True) == {"key": True, "key2": False, "key3": None}
262
265
  assert repair_json('{"key": true, "key2": false, "key3": }', skip_json_loads=True) == '{"key": true, "key2": false, "key3": ""}'
263
266
  assert loads('{"key": true, "key2": false, "key3": }', skip_json_loads=True) == {"key": True, "key2": False, "key3": ""}
264
267
 
268
+
265
269
  def test_repair_json_from_file():
266
270
  import os
267
271
  import tempfile
File without changes
File without changes
File without changes