Some problems with reading json in python

I want to get json data in dictionary type, but i can only get it in list type.

[
    {
        "name": "...",
        "phones": [
            {
                "description": "...",
                "number": "..."
            },
            {
                "description": "...",
                "number": "..."
            }
        ]
    }
]

How can I get this json data in dict type?

  • Hi! Welcome to StackOverflow! Please take a look at our tour to get a better understanding about how to ask a good question. Afterwards, please edit your question to add all the relevant code.

    – 

  • The outermost brackets are [], so this is a list. Do you want to access the first element in that list, i.e. an object? Then do that with data[0]

    – 

  • Can you share what this dictionary would look like? Are you just wanting mydict=json.loads(yourdata)[0]?

    – 

  • It’s a list of dictionaries, because your JSON is an array of objects. If you want a different structure, use a different structure.

    – 

  • 1

    dict(enumerate(somelist)) will create a dictionary whose keys are the list indexes.

    – 

Leave a Comment