json-repair 0.29.1__tar.gz → 0.29.2__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.1
3
+ Version: 0.29.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
@@ -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.29.1"
6
+ version = "0.29.2"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -384,38 +384,39 @@ class JSONParser:
384
384
  # * If we are fixing missing quotes in an object, when it finds the special terminators
385
385
  char = self.get_char_at()
386
386
  while char and char != rstring_delimiter:
387
- if missing_quotes:
388
- if self.get_context() == "object_key" and (
389
- char == ":" or char.isspace()
390
- ):
387
+ if (
388
+ missing_quotes
389
+ and self.get_context() == "object_key"
390
+ and (char == ":" or char.isspace())
391
+ ):
392
+ self.log(
393
+ "While parsing a string missing the left delimiter in object key context, we found a :, stopping here",
394
+ "info",
395
+ )
396
+ break
397
+ if self.get_context() == "object_value" and char in [",", "}"]:
398
+ rstring_delimiter_missing = True
399
+ # check if this is a case in which the closing comma is NOT missing instead
400
+ i = 1
401
+ next_c = self.get_char_at(i)
402
+ while next_c and next_c != rstring_delimiter:
403
+ i += 1
404
+ next_c = self.get_char_at(i)
405
+ if next_c:
406
+ i += 1
407
+ next_c = self.get_char_at(i)
408
+ # found a delimiter, now we need to check that is followed strictly by a comma or brace
409
+ while next_c and next_c.isspace():
410
+ i += 1
411
+ next_c = self.get_char_at(i)
412
+ if next_c and next_c in [",", "}"]:
413
+ rstring_delimiter_missing = False
414
+ if rstring_delimiter_missing:
391
415
  self.log(
392
- "While parsing a string missing the left delimiter in object key context, we found a :, stopping here",
416
+ "While parsing a string missing the left delimiter in object value context, we found a , or } and we couldn't determine that a right delimiter was present. Stopping here",
393
417
  "info",
394
418
  )
395
419
  break
396
- elif self.get_context() == "object_value" and char in [",", "}"]:
397
- rstring_delimiter_missing = True
398
- # check if this is a case in which the closing comma is NOT missing instead
399
- i = 1
400
- next_c = self.get_char_at(i)
401
- while next_c and next_c != rstring_delimiter:
402
- i += 1
403
- next_c = self.get_char_at(i)
404
- if next_c:
405
- i += 1
406
- next_c = self.get_char_at(i)
407
- # found a delimiter, now we need to check that is followed strictly by a comma or brace
408
- while next_c and next_c.isspace():
409
- i += 1
410
- next_c = self.get_char_at(i)
411
- if next_c and next_c in [",", "}"]:
412
- rstring_delimiter_missing = False
413
- if rstring_delimiter_missing:
414
- self.log(
415
- "While parsing a string missing the left delimiter in object value context, we found a , or } and we couldn't determine that a right delimiter was present. Stopping here",
416
- "info",
417
- )
418
- break
419
420
  string_acc += char
420
421
  self.index += 1
421
422
  char = self.get_char_at()
@@ -507,7 +508,7 @@ class JSONParser:
507
508
  if next_c == "}":
508
509
  # OK this is valid then
509
510
  self.log(
510
- "While parsing a string, we a misplaced quote that would have closed the string but has a different meaning here since this is the last element of the object, ignoring it",
511
+ "While parsing a string, we misplaced a quote that would have closed the string but has a different meaning here since this is the last element of the object, ignoring it",
511
512
  "info",
512
513
  )
513
514
  string_acc += str(char)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.1
3
+ Version: 0.29.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
@@ -98,6 +98,8 @@ def test_missing_and_mixed_quotes():
98
98
  repair_json('{"name": "John", "age": 30, "city": "New')
99
99
  == '{"name": "John", "age": 30, "city": "New"}'
100
100
  )
101
+ assert repair_json('{"name": "John", "age": 30, "city": "New York, "gender": "male"}') == '{"name": "John", "age": 30, "city": "New York", "gender": "male"}'
102
+
101
103
  assert repair_json('[{"key": "value", COMMENT "notes": "lorem "ipsum", sic." }]') == '[{"key": "value", "notes": "lorem \\"ipsum\\", sic."}]'
102
104
  assert repair_json('{"key": ""value"}') == '{"key": "value"}'
103
105
  assert repair_json('{"key": "value", 5: "value"}') == '{"key": "value", "5": "value"}'
@@ -19,7 +19,7 @@ def test_true_true_correct(benchmark):
19
19
  mean_time = benchmark.stats.get("median")
20
20
 
21
21
  # Define your time threshold in seconds
22
- max_time = 15 / 10 ** 4 # 1.5 millisecond
22
+ max_time = 2 / 10 ** 3 # 2 millisecond
23
23
 
24
24
  # Assert that the average time is below the threshold
25
25
  assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
@@ -31,7 +31,7 @@ def test_true_true_incorrect(benchmark):
31
31
  mean_time = benchmark.stats.get("median")
32
32
 
33
33
  # Define your time threshold in seconds
34
- max_time = 15 / 10 ** 4 # 1.5 millisecond
34
+ max_time = 2 / 10 ** 3 # 2 millisecond
35
35
 
36
36
  # Assert that the average time is below the threshold
37
37
  assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
@@ -53,7 +53,7 @@ def test_true_false_incorrect(benchmark):
53
53
  mean_time = benchmark.stats.get("median")
54
54
 
55
55
  # Define your time threshold in seconds
56
- max_time = 15 / 10 ** 4 # 1.5 millisecond
56
+ max_time = 2 / 10 ** 3 # 2 millisecond
57
57
 
58
58
  # Assert that the average time is below the threshold
59
59
  assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
@@ -64,7 +64,7 @@ def test_false_true_correct(benchmark):
64
64
  mean_time = benchmark.stats.get("median")
65
65
 
66
66
  # Define your time threshold in seconds
67
- max_time = 15 / 10 ** 4 # 1.5 millisecond
67
+ max_time = 2 / 10 ** 3 # 2 millisecond
68
68
 
69
69
  # Assert that the average time is below the threshold
70
70
  assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
@@ -75,7 +75,7 @@ def test_false_true_incorrect(benchmark):
75
75
  mean_time = benchmark.stats.get("median")
76
76
 
77
77
  # Define your time threshold in seconds
78
- max_time = 15 / 10 ** 4 # 1.5 millisecond
78
+ max_time = 2 / 10 ** 3 # 2 millisecond
79
79
 
80
80
  # Assert that the average time is below the threshold
81
81
  assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
@@ -97,7 +97,7 @@ def test_false_false_incorrect(benchmark):
97
97
  mean_time = benchmark.stats.get("median")
98
98
 
99
99
  # Define your time threshold in seconds
100
- max_time = 15 / 10 ** 4 # 1.5 millisecond
100
+ max_time = 2 / 10 ** 3 # 2 millisecond
101
101
 
102
102
  # Assert that the average time is below the threshold
103
103
  assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
File without changes
File without changes
File without changes