Wilsntn
Wilsntn

Reputation: 9

List inside list in a json file

Hi im trying to parse a json file and this file have a couple lists inside this is the json

[
            {
                "id": "123123"
                "genres": [
                    "Drama",
                    "Music"
                ],
                "date": [
                    {
                        "date_uploaded": "2022-04-25 15:34:36",
                        "date_uploaded_unix": 1650893676
                    },
                    {
                       
                        "date_uploaded_unix": 1650905862
                    }
                ],
                "date_uploaded": "2022-04-25 15:34:36",
                "date_uploaded_unix": 1650893676
            }
]

i've tried

import json

with open('movie.json') as json_data:
    lista_objeto = json.load(json_data)

for i in lista_objeto:    
    if type(lista_objeto) == list:
        coluna = list(i.keys())

then i got the primary keys and thats awesome to insert in my database columns but i cant get the values inside of the lists to put inside the columns in my database and i didnt figure out how to list the contents of the lists..

how can i get the specific first content of every list inside my list for example i want to get just the first object inside the list ["genres": "drama"]

Upvotes: 0

Views: 1786

Answers (1)

YadneshD
YadneshD

Reputation: 567

As per your JSON, it looks like it is a list of python dictionaries (hashmaps). You can parse each individual dictionary inside those lists. To get first object of genres, try:

for i in lista_objeto:
    print(i["genres"][0])

You should be able to get first object of genre present in each dictionary of the list.

Upvotes: 2

Related Questions