IndexError: list index out of range, when formatting

0

I'm trying to format a file, my problem is that if inside "", there is an extra quote ("" ") thunders & throws this error, my code is as follows:

with open(entrada, "r") as fichero:
    datos = fichero.read()
    datos = list(datos)
indice=0
while indice < len(datos):
if datos[indice]=="\"":
    indice+=1
        while (datos[indice]!="\"" and datos[indice+1]!=":") or (datos[indice]!="\"" and datos[indice+1]!=",") or (datos[indice]!="\"" and datos[indice+1]!="}") and (indice+2<len(datos)):
        indice+=1
    if datos[indice]==",":
        datos[indice]=",\n"
    if datos[indice]=="[":
        datos[indice]="[\n"
    if datos[indice]=="{":
        datos[indice]="{\n"
    indice+=1
datos = ''.join(str(e) for e in datos)

I hope you can help me, maybe you will realize that it is to format a JSON, & that I can use the dump & the load, but it does not work for me since I'm trying to format a JSON that has syntax errors.

    
asked by Pony94 19.04.2018 в 02:42
source

0 answers