close

[Solved] Python and JSON – Type list indices must be integers not str

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python and JSON – Type list indices must be integers not str in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python and JSON – Type list indices must be integers not str Error Occurs?

Today I get the following error Python and JSON – Type list indices must be integers not str in python.

How To Solve Python and JSON – Type list indices must be integers not str Error ?

  1. How To Solve Python and JSON – Type list indices must be integers not str Error ?

    To Solve Python and JSON – Type list indices must be integers not str Error First of all, you should be using json.loads, not json.dumpsloads converts JSON source text to a Python value, while dumps goes the other way.

  2. Python and JSON – Type list indices must be integers not str

    To Solve Python and JSON – Type list indices must be integers not str Error First of all, you should be using json.loads, not json.dumpsloads converts JSON source text to a Python value, while dumps goes the other way.

Solution 1

First of all, you should be using json.loads, not json.dumpsloads converts JSON source text to a Python value, while dumps goes the other way.

After you fix that, based on the JSON snippet at the top of your question, readable_json will be a list, and so readable_json['firstName'] is meaningless. The correct way to get the 'firstName' field of every element of a list is to eliminate the playerstuff = readable_json['firstName'] line and change for i in playerstuff: to for i in readable_json:.

Solution 2

I solved changing

readable_json['firstName']

by

readable_json[0]['firstName']

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read