json-repair 0.42.0__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.
@@ -113,7 +113,7 @@ class JSONParser:
113
113
 
114
114
  def parse_object(self) -> Dict[str, JSONReturnType]:
115
115
  # <object> ::= '{' [ <member> *(', ' <member>) ] '}' ; A sequence of 'members'
116
- obj = {}
116
+ obj: Dict[str, JSONReturnType] = {}
117
117
  # Stop when you either find the closing parentheses or you have iterated over the entire string
118
118
  while (self.get_char_at() or "}") != "}":
119
119
  # This is what we expect to find:
@@ -141,6 +141,27 @@ class JSONParser:
141
141
  while self.get_char_at():
142
142
  # The rollback index needs to be updated here in case the key is empty
143
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
144
165
  key = str(self.parse_string())
145
166
  if key == "":
146
167
  self.skip_whitespaces_at()
@@ -216,7 +237,7 @@ class JSONParser:
216
237
 
217
238
  # skip over whitespace after a value but before closing ]
218
239
  char = self.get_char_at()
219
- while char and (char.isspace() or char == ","):
240
+ while char and char != "]" and (char.isspace() or char == ","):
220
241
  self.index += 1
221
242
  char = self.get_char_at()
222
243
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.42.0
3
+ Version: 0.43.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
@@ -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=bu8FBxaazJ_tRJQmdZA7Me68HD7t3JuReVgjvyGWbmQ,39174
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.42.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
10
- json_repair-0.42.0.dist-info/METADATA,sha256=XJXQxqg6znbpuxK1hTY_0v3FB4KtH_8gOMPD-u_EdvY,11860
11
- json_repair-0.42.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
12
- json_repair-0.42.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
13
- json_repair-0.42.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
14
- json_repair-0.42.0.dist-info/RECORD,,
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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.0)
2
+ Generator: setuptools (80.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5