Home > Software design >  List has no attribute 'keys' when writing to CSV in Python
List has no attribute 'keys' when writing to CSV in Python

Time:07-04

I am making a Python Script which fetches JSON from an endpoint and then writes it to a CSV, however I keep getting this error when trying to write a specific key. What should I do?

My code and the error I am receiving

What JSON data looks like

What I am aiming to have in the end

CodePudding user response:

Results is a list of dictionaries. try doing Results[0].keys() instead

CodePudding user response:

"Results" is of type list and not dict.
Therefore, you can't treat it like a dictionary and invoke keys()

I guess what you want to do is remove the '[' ']' from "Results" in your json file

  • Related