json-repair 0.41.1__py3-none-any.whl → 0.43.0__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_parser.py +29 -4
- {json_repair-0.41.1.dist-info → json_repair-0.43.0.dist-info}/METADATA +1 -1
- {json_repair-0.41.1.dist-info → json_repair-0.43.0.dist-info}/RECORD +7 -7
- {json_repair-0.41.1.dist-info → json_repair-0.43.0.dist-info}/WHEEL +1 -1
- {json_repair-0.41.1.dist-info → json_repair-0.43.0.dist-info}/entry_points.txt +0 -0
- {json_repair-0.41.1.dist-info → json_repair-0.43.0.dist-info}/licenses/LICENSE +0 -0
- {json_repair-0.41.1.dist-info → json_repair-0.43.0.dist-info}/top_level.txt +0 -0
json_repair/json_parser.py
CHANGED
@@ -10,7 +10,6 @@ JSONReturnType = Union[Dict[str, Any], List[Any], str, float, int, bool, None]
|
|
10
10
|
class JSONParser:
|
11
11
|
# Constants
|
12
12
|
STRING_DELIMITERS = ['"', "'", "“", "”"]
|
13
|
-
NUMBER_CHARS = set("0123456789-.eE/,")
|
14
13
|
|
15
14
|
def __init__(
|
16
15
|
self,
|
@@ -114,7 +113,7 @@ class JSONParser:
|
|
114
113
|
|
115
114
|
def parse_object(self) -> Dict[str, JSONReturnType]:
|
116
115
|
# <object> ::= '{' [ <member> *(', ' <member>) ] '}' ; A sequence of 'members'
|
117
|
-
obj = {}
|
116
|
+
obj: Dict[str, JSONReturnType] = {}
|
118
117
|
# Stop when you either find the closing parentheses or you have iterated over the entire string
|
119
118
|
while (self.get_char_at() or "}") != "}":
|
120
119
|
# This is what we expect to find:
|
@@ -142,6 +141,27 @@ class JSONParser:
|
|
142
141
|
while self.get_char_at():
|
143
142
|
# The rollback index needs to be updated here in case the key is empty
|
144
143
|
rollback_index = self.index
|
144
|
+
if self.get_char_at() == "[" and key == "":
|
145
|
+
# Is this an array?
|
146
|
+
# Need to check if the previous parsed value contained in obj is an array and in that case parse and merge the two
|
147
|
+
prev_key = list(obj.keys())[-1] if obj else None
|
148
|
+
if prev_key and isinstance(obj[prev_key], list):
|
149
|
+
# If the previous key's value is an array, parse the new array and merge
|
150
|
+
self.index += 1
|
151
|
+
new_array = self.parse_array()
|
152
|
+
if isinstance(new_array, list):
|
153
|
+
# Merge and flatten the arrays
|
154
|
+
prev_value = obj[prev_key]
|
155
|
+
if isinstance(prev_value, list):
|
156
|
+
prev_value.extend(
|
157
|
+
new_array[0]
|
158
|
+
if len(new_array) == 1
|
159
|
+
and isinstance(new_array[0], list)
|
160
|
+
else new_array
|
161
|
+
)
|
162
|
+
continue
|
163
|
+
else:
|
164
|
+
self.index = rollback_index
|
145
165
|
key = str(self.parse_string())
|
146
166
|
if key == "":
|
147
167
|
self.skip_whitespaces_at()
|
@@ -217,7 +237,7 @@ class JSONParser:
|
|
217
237
|
|
218
238
|
# skip over whitespace after a value but before closing ]
|
219
239
|
char = self.get_char_at()
|
220
|
-
while char and (char.isspace() or char == ","):
|
240
|
+
while char and char != "]" and (char.isspace() or char == ","):
|
221
241
|
self.index += 1
|
222
242
|
char = self.get_char_at()
|
223
243
|
|
@@ -663,7 +683,8 @@ class JSONParser:
|
|
663
683
|
number_str = ""
|
664
684
|
char = self.get_char_at()
|
665
685
|
is_array = self.context.current == ContextValues.ARRAY
|
666
|
-
|
686
|
+
NUMBER_CHARS = set("0123456789-.eE/,")
|
687
|
+
while char and char in NUMBER_CHARS and (not is_array or char != ","):
|
667
688
|
number_str += char
|
668
689
|
self.index += 1
|
669
690
|
char = self.get_char_at()
|
@@ -671,6 +692,10 @@ class JSONParser:
|
|
671
692
|
# The number ends with a non valid character for a number/currency, rolling back one
|
672
693
|
number_str = number_str[:-1]
|
673
694
|
self.index -= 1
|
695
|
+
elif (self.get_char_at() or "").isalpha():
|
696
|
+
# this was a string instead, sorry
|
697
|
+
self.index -= len(number_str)
|
698
|
+
return self.parse_string()
|
674
699
|
try:
|
675
700
|
if "," in number_str:
|
676
701
|
return str(number_str)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
json_repair/__init__.py,sha256=c4L2kZrHvWEKfj_ODU2naliNuvU6FlFVxtF0hbLe6s8,178
|
2
2
|
json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
|
3
3
|
json_repair/json_context.py,sha256=mm6dOyrPJ1sDskTORZSXCW7W9-5veMlUKqXQ3Hw3EG4,971
|
4
|
-
json_repair/json_parser.py,sha256=
|
4
|
+
json_repair/json_parser.py,sha256=GFziN2KELYDWElzPda5wPfSeFIHYF8enJSr0c2YzKmQ,40451
|
5
5
|
json_repair/json_repair.py,sha256=k-5HRRlCqrxNmJi0u1KE3IUeL4HXqi1XZ7oAL-NFDLo,10314
|
6
6
|
json_repair/object_comparer.py,sha256=SeicB6_N4BHAEPon7s2BELEaJc4oyR9ZhfX2RgPk6Bw,1682
|
7
7
|
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
json_repair/string_file_wrapper.py,sha256=koZmdq2-Z5K7XF1bDqX6dEbNaVMJYcMTjq-aGe6NQvA,4526
|
9
|
-
json_repair-0.
|
10
|
-
json_repair-0.
|
11
|
-
json_repair-0.
|
12
|
-
json_repair-0.
|
13
|
-
json_repair-0.
|
14
|
-
json_repair-0.
|
9
|
+
json_repair-0.43.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
10
|
+
json_repair-0.43.0.dist-info/METADATA,sha256=fR8K3LENGHxwkjG2pVRedVsh6XGBq0JWPV3weLz1KIM,11860
|
11
|
+
json_repair-0.43.0.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
12
|
+
json_repair-0.43.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
13
|
+
json_repair-0.43.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
14
|
+
json_repair-0.43.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|