json-repair 0.28.1__py3-none-any.whl → 0.28.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.
- json_repair/json_repair.py +12 -102
- {json_repair-0.28.1.dist-info → json_repair-0.28.2.dist-info}/METADATA +1 -1
- json_repair-0.28.2.dist-info/RECORD +8 -0
- json_repair-0.28.1.dist-info/RECORD +0 -8
- {json_repair-0.28.1.dist-info → json_repair-0.28.2.dist-info}/LICENSE +0 -0
- {json_repair-0.28.1.dist-info → json_repair-0.28.2.dist-info}/WHEEL +0 -0
- {json_repair-0.28.1.dist-info → json_repair-0.28.2.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -24,7 +24,7 @@ All supported use cases are in the unit tests
|
|
24
24
|
|
25
25
|
import os
|
26
26
|
import json
|
27
|
-
from typing import Any, Dict, List, Optional, Union, TextIO, Tuple,
|
27
|
+
from typing import Any, Dict, List, Optional, Union, TextIO, Tuple, Literal
|
28
28
|
|
29
29
|
|
30
30
|
class StringFileWrapper:
|
@@ -33,7 +33,7 @@ class StringFileWrapper:
|
|
33
33
|
self.fd = fd
|
34
34
|
self.length: int = 0
|
35
35
|
|
36
|
-
def __getitem__(self, index: int) -> str:
|
36
|
+
def __getitem__(self, index: int | slice) -> str:
|
37
37
|
if isinstance(index, slice):
|
38
38
|
self.fd.seek(index.start)
|
39
39
|
value = self.fd.read(index.stop - index.start)
|
@@ -564,7 +564,7 @@ class JSONParser:
|
|
564
564
|
# <boolean> is one of the literal strings 'true', 'false', or 'null' (unquoted)
|
565
565
|
starting_index = self.index
|
566
566
|
char = (self.get_char_at() or "").lower()
|
567
|
-
value
|
567
|
+
value: Optional[Tuple[str, Optional[bool]]]
|
568
568
|
if char == "t":
|
569
569
|
value = ("true", True)
|
570
570
|
elif char == "f":
|
@@ -632,57 +632,13 @@ class JSONParser:
|
|
632
632
|
)
|
633
633
|
|
634
634
|
|
635
|
-
@overload
|
636
635
|
def repair_json(
|
637
636
|
json_str: str = "",
|
638
|
-
return_objects:
|
639
|
-
skip_json_loads:
|
640
|
-
logging:
|
637
|
+
return_objects: bool = False,
|
638
|
+
skip_json_loads: bool = False,
|
639
|
+
logging: bool = False,
|
641
640
|
json_fd: Optional[TextIO] = None,
|
642
|
-
ensure_ascii:
|
643
|
-
) -> str: ...
|
644
|
-
|
645
|
-
|
646
|
-
@overload
|
647
|
-
def repair_json(
|
648
|
-
json_str: str = "",
|
649
|
-
return_objects: Literal[True] = True,
|
650
|
-
skip_json_loads: Optional[bool] = False,
|
651
|
-
logging: Optional[Literal[False]] = False, # None is treated as False
|
652
|
-
json_fd: Optional[TextIO] = None,
|
653
|
-
ensure_ascii: Optional[bool] = True,
|
654
|
-
) -> JSONReturnType: ...
|
655
|
-
|
656
|
-
|
657
|
-
@overload
|
658
|
-
def repair_json(
|
659
|
-
json_str: str = "",
|
660
|
-
return_objects: Optional[Literal[False]] = False, # None is treated as False
|
661
|
-
skip_json_loads: Optional[bool] = False,
|
662
|
-
logging: Literal[True] = True,
|
663
|
-
json_fd: Optional[TextIO] = None,
|
664
|
-
ensure_ascii: Optional[bool] = True,
|
665
|
-
) -> Tuple[str, List[Dict[str, str]]]: ...
|
666
|
-
|
667
|
-
|
668
|
-
@overload
|
669
|
-
def repair_json(
|
670
|
-
json_str: str = "",
|
671
|
-
return_objects: Literal[True] = True,
|
672
|
-
skip_json_loads: Optional[bool] = False,
|
673
|
-
logging: Literal[True] = True,
|
674
|
-
json_fd: Optional[TextIO] = None,
|
675
|
-
ensure_ascii: Optional[bool] = True,
|
676
|
-
) -> Tuple[JSONReturnType, List[Dict[str, str]]]: ...
|
677
|
-
|
678
|
-
|
679
|
-
def repair_json(
|
680
|
-
json_str: str = "",
|
681
|
-
return_objects: Optional[bool] = False,
|
682
|
-
skip_json_loads: Optional[bool] = False,
|
683
|
-
logging: Optional[bool] = False,
|
684
|
-
json_fd: Optional[TextIO] = None,
|
685
|
-
ensure_ascii: Optional[bool] = True,
|
641
|
+
ensure_ascii: bool = True,
|
686
642
|
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]:
|
687
643
|
"""
|
688
644
|
Given a json formatted string, it will try to decode it and, if it fails, it will try to fix it.
|
@@ -709,26 +665,10 @@ def repair_json(
|
|
709
665
|
return json.dumps(parsed_json, ensure_ascii=ensure_ascii)
|
710
666
|
|
711
667
|
|
712
|
-
@overload
|
713
|
-
def loads(
|
714
|
-
json_str: str,
|
715
|
-
skip_json_loads: Optional[bool] = False,
|
716
|
-
logging: Optional[Literal[False]] = False, # None is treated as False
|
717
|
-
) -> JSONReturnType: ...
|
718
|
-
|
719
|
-
|
720
|
-
@overload
|
721
668
|
def loads(
|
722
669
|
json_str: str,
|
723
|
-
skip_json_loads:
|
724
|
-
logging:
|
725
|
-
) -> Tuple[JSONReturnType, List[Dict[str, str]]]: ...
|
726
|
-
|
727
|
-
|
728
|
-
def loads(
|
729
|
-
json_str: str,
|
730
|
-
skip_json_loads: Optional[bool] = False,
|
731
|
-
logging: Optional[bool] = False,
|
670
|
+
skip_json_loads: bool = False,
|
671
|
+
logging: bool = False,
|
732
672
|
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]:
|
733
673
|
"""
|
734
674
|
This function works like `json.loads()` except that it will fix your JSON in the process.
|
@@ -742,22 +682,8 @@ def loads(
|
|
742
682
|
)
|
743
683
|
|
744
684
|
|
745
|
-
@overload
|
746
685
|
def load(
|
747
|
-
fd: TextIO,
|
748
|
-
skip_json_loads: Optional[bool] = False,
|
749
|
-
logging: Optional[Literal[False]] = False,
|
750
|
-
) -> JSONReturnType: ...
|
751
|
-
|
752
|
-
|
753
|
-
@overload
|
754
|
-
def load(
|
755
|
-
fd: TextIO, skip_json_loads: Optional[bool] = False, logging: Literal[True] = True
|
756
|
-
) -> Tuple[JSONReturnType, List[Dict[str, str]]]: ...
|
757
|
-
|
758
|
-
|
759
|
-
def load(
|
760
|
-
fd: TextIO, skip_json_loads: Optional[bool] = False, logging: Optional[bool] = False
|
686
|
+
fd: TextIO, skip_json_loads: bool = False, logging: bool = False
|
761
687
|
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]:
|
762
688
|
"""
|
763
689
|
This function works like `json.load()` except that it will fix your JSON in the process.
|
@@ -771,26 +697,10 @@ def load(
|
|
771
697
|
)
|
772
698
|
|
773
699
|
|
774
|
-
@overload
|
775
|
-
def from_file(
|
776
|
-
filename: str,
|
777
|
-
skip_json_loads: Optional[bool] = False,
|
778
|
-
logging: Optional[Literal[False]] = False,
|
779
|
-
) -> JSONReturnType: ...
|
780
|
-
|
781
|
-
|
782
|
-
@overload
|
783
|
-
def from_file(
|
784
|
-
filename: str,
|
785
|
-
skip_json_loads: Optional[bool] = False,
|
786
|
-
logging: Literal[True] = True,
|
787
|
-
) -> Tuple[JSONReturnType, List[Dict[str, str]]]: ...
|
788
|
-
|
789
|
-
|
790
700
|
def from_file(
|
791
701
|
filename: str,
|
792
|
-
skip_json_loads:
|
793
|
-
logging:
|
702
|
+
skip_json_loads: bool = False,
|
703
|
+
logging: bool = False,
|
794
704
|
) -> Union[JSONReturnType, Tuple[JSONReturnType, List[Dict[str, str]]]]:
|
795
705
|
"""
|
796
706
|
This function is a wrapper around `load()` so you can pass the filename as string
|
@@ -0,0 +1,8 @@
|
|
1
|
+
json_repair/__init__.py,sha256=IIzSm1DsCRrr8seF3UeMZXwxcq-tE3j-8d1WBxvEJvE,178
|
2
|
+
json_repair/json_repair.py,sha256=v43na-l2g34pwTZH5FDljI_r5ArIaZfCeHW_LbB8puw,30123
|
3
|
+
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
json_repair-0.28.2.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
5
|
+
json_repair-0.28.2.dist-info/METADATA,sha256=llPJ1A8UePeGKbPSkC6-b2kE2somdgSMiq-wuPANGZ8,8043
|
6
|
+
json_repair-0.28.2.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
|
7
|
+
json_repair-0.28.2.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
8
|
+
json_repair-0.28.2.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=IIzSm1DsCRrr8seF3UeMZXwxcq-tE3j-8d1WBxvEJvE,178
|
2
|
-
json_repair/json_repair.py,sha256=_NBAaY6iqIp1cB1W-lnQ3uS6nc5DjZZyf_HeklYmDyY,32502
|
3
|
-
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
json_repair-0.28.1.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
5
|
-
json_repair-0.28.1.dist-info/METADATA,sha256=i9SaIoWFc7YjuQLLN1Rd8GsmVAy0rWJ9-fNwsVDR_KA,8043
|
6
|
-
json_repair-0.28.1.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
|
7
|
-
json_repair-0.28.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
8
|
-
json_repair-0.28.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|