Unable to understand the runtime error


#1

HI,
This is my code:
class Solution:
# @param A : string
# @return a list of strings
def prettyJSON(self, A):
if not A:
return

    indent = 0
    key = True
    result = ["" for i in range(len(A))]
    j = 0

    for i in range(len(A)):
        if A[i] in ['{', '[']:                
            if indent >= 0:
                result[j] += A[i].rjust(indent+1)
                j += 1

            indent += 1

        elif A[i] == ":":
            key = False
            result[j] += A[i]
            if A[i+1] in ['{', '[']:
                j += 1
                key = True
        
        elif A[i] == ",":
            key = True
            result[j] += A[i]
            j +=1

        elif A[i] in ['}', ']']:
            indent -= 1
            result[j] += A[i].rjust(indent+ 1)
            j += 1
            
        else:
            if A[i] == " ":
                continue
            
            if indent >= 1 and key:
                result[j] += A[i].rjust(indent+ 1)
                key = False
            else:
                result[j] += A[i]

            if A[i+1] in ['}', ']']:
                j += 1
        i += 1

    for res in range(len(result)):
        if not result[res]:
            break
        print(result[res])

#2

class Solution:
# @param A : string
# @return a list of strings
def prettyJSON(self, A):
if not A:
return

    indent = 0
    key = True
    result = ["" for i in range(len(A))]
    j = 0

    for i in range(len(A)):
        if A[i] in ['{', '[']: 
            if indent == 0:
                result[j] += A[i]
            elif indent > 0:
                result[j] += A[i].rjust(indent+1)
            j += 1

            indent += 4

        elif A[i] == ":":
            key = False
            result[j] += A[i]
            if A[i+1] in ['{', '[']:
                j += 1
                key = True
        
        elif A[i] == ",":
            key = True
            result[j] += A[i]
            j +=1

        elif A[i] in ['}', ']']:
            indent -= 4
            result[j] += A[i].rjust(indent+1)
            j += 1
            
        else:
            if A[i] == " ":
                continue
            
            if indent >= 1 and key:
                result[j] += A[i].rjust(indent+1)
                key = False
            else:
                result[j] += A[i]

            if A[i+1] in ['}', ']']:
                j += 1
        i += 1
    
    res = 0
    for res in range(len(result)):
        if not result[res]:
            break
    
    return result[:res]

#3

Why my output is not correct?