Iterate through this json object

Question:

Hi I am trying to iterate through this json obtect I have tried all and it does not work


{
    "results": [
        {
            "added_date": "Mon, 07 Nov 2022 14:42:14 GMT",
            "born_date": "Mon, 07 Nov 2022 14:42:14 GMT",
            "cellphone": "93545887778",
            "father_lastname": "Mendez",
            "gender_id": 1,
            "id": 1,
            "mother_lastname": "Huerta",
            "names": "Luis",
            "nationality_id": 1,
            "picture": null,
            "rut": "2233229-8",
            "updated_date": "Mon, 07 Nov 2022 14:42:14 GMT"
        }
    ]
}

How can I do the foreach or the for I have tried this

`

for employee in employees.items()

`
it does not work

How can I do that?

Asked By: Jis

||

Answers:

Your question is weird like you are iterating through employees and you didn’t mention what employees are. I am assuming employees are the results.

your_json = {
    "results": [
        {
            "added_date": "Mon, 07 Nov 2022 14:42:14 GMT",
            "born_date": "Mon, 07 Nov 2022 14:42:14 GMT",
            "cellphone": "93545887778",
            "father_lastname": "Mendez",
            "gender_id": 1,
            "id": 1,
            "mother_lastname": "Huerta",
            "names": "Luis",
            "nationality_id": 1,
            "picture": None,
            "rut": "2233229-8",
            "updated_date": "Mon, 07 Nov 2022 14:42:14 GMT"
        }
    ]
}
for result in your_json.get('results'):
    print(result)
    print(result.get("names"))
Answered By: Mubashar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.