json-repair 0.24.0__tar.gz → 0.25.0__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.24.0
3
+ Version: 0.25.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
@@ -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.24.0"
6
+ version = "0.25.0"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -370,6 +370,10 @@ class JSONParser:
370
370
  if self.get_context() == "object_key" and (
371
371
  char == ":" or char.isspace()
372
372
  ):
373
+ self.log(
374
+ "While parsing a string missing the left delimiter in object key context, we found a :, stopping here",
375
+ "info",
376
+ )
373
377
  break
374
378
  elif self.get_context() == "object_value" and char in [",", "}"]:
375
379
  rstring_delimiter_missing = True
@@ -389,6 +393,10 @@ class JSONParser:
389
393
  if next_c and next_c in [",", "}"]:
390
394
  rstring_delimiter_missing = False
391
395
  if rstring_delimiter_missing:
396
+ self.log(
397
+ "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",
398
+ "info",
399
+ )
392
400
  break
393
401
  string_acc += char
394
402
  self.index += 1
@@ -410,6 +418,33 @@ class JSONParser:
410
418
  "While parsing a string, we found a doubled quote, ignoring it",
411
419
  "info",
412
420
  )
421
+ elif missing_quotes and self.get_context() == "object_value":
422
+ # In case of missing starting quote I need to check if the delimeter is the end or the beginning of a key
423
+ i = 1
424
+ next_c = self.get_char_at(i)
425
+ while next_c and next_c not in [
426
+ rstring_delimiter,
427
+ lstring_delimiter,
428
+ ]:
429
+ i += 1
430
+ next_c = self.get_char_at(i)
431
+ if next_c:
432
+ # We found a quote, now let's make sure there's a ":" following
433
+ i += 1
434
+ next_c = self.get_char_at(i)
435
+ # found a delimiter, now we need to check that is followed strictly by a comma or brace
436
+ while next_c and next_c.isspace():
437
+ i += 1
438
+ next_c = self.get_char_at(i)
439
+ if next_c and next_c == ":":
440
+ # Reset the cursor
441
+ self.index -= 1
442
+ char = self.get_char_at()
443
+ self.log(
444
+ "In a string with missing quotes and object value context, I found a delimeter but it turns out it was the beginning on the next key. Stopping here.",
445
+ "info",
446
+ )
447
+ break
413
448
  else:
414
449
  # Check if eventually there is a rstring delimiter, otherwise we bail
415
450
  i = 1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.24.0
3
+ Version: 0.25.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
@@ -142,6 +142,7 @@ def test_object_edge_cases():
142
142
  assert repair_json("""{"b": "xxxxx" true}""") == '{"b": "xxxxx"}'
143
143
  assert repair_json('{"key": "Lorem "ipsum" s,"}') == '{"key": "Lorem \\"ipsum\\" s,"}'
144
144
  assert repair_json('{"lorem": ipsum, sic, datum.",}') == '{"lorem": "ipsum, sic, datum."}'
145
+ assert repair_json('{"lorem": sic tamet. "ipsum": sic tamet, quick brown fox. "sic": ipsum}') == '{"lorem": "sic tamet.", "ipsum": "sic tamet", "sic": "ipsum"}'
145
146
 
146
147
  def test_number_edge_cases():
147
148
  assert repair_json(' - { "test_key": ["test_value", "test_value2"] }') == '{"test_key": ["test_value", "test_value2"]}'
@@ -243,7 +244,7 @@ def test_repair_json_from_file():
243
244
  # Write content to the temporary file
244
245
  with os.fdopen(temp_fd, 'w') as tmp:
245
246
  tmp.write("{key:value}")
246
- assert(from_file(temp_path, logging=True)) == ({'key': 'value'}, [{'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}, {'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}])
247
+ assert(from_file(temp_path, logging=True)) == ({'key': 'value'}, [{'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'context': '{key:value}', 'text': 'While parsing a string missing the left delimiter in object key context, we found a :, stopping here',}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}, {'text': 'While parsing a string, we found a literal instead of a quote', 'context': '{key:value}'}, {'text': 'While parsing a string, we found no starting quote. Will add the quote back', 'context': '{key:value}'}, {'context': '{key:value}', 'text': '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'}, {'text': 'While parsing a string, we missed the closing quote, ignoring', 'context': '{key:value}'}])
247
248
  finally:
248
249
  # Clean up - delete the temporary file
249
250
  os.remove(temp_path)
File without changes
File without changes
File without changes