Link to home
Start Free TrialLog in
Avatar of angel7170
angel7170Flag for United States of America

asked on

Read JSON and Write to CSV using Python

Hello,

We have a JSON file that we are trying to read and put the Key and the values in a CSV file. We are getting an error as below. can someone please help?

Attached is the sample JSON file and the Python code we are using.

Our program Parse_workitem.py accepts 2 arguments one is  input_file which is json and the other one is output_file which is csv. When we execute the code as below with both arguments the code is failing with the following error. We are using Python version 2.7.5


./parse_workitem.py --input_file /home/dqadmin/json/work_items.json  --output_file /home/dqadmin/json/work_items.csv
Traceback (most recent call last):
  File "./parse_workitem.py", line 66, in <module>
    main()
  File "./parse_workitem.py", line 54, in main
    value = item.get(key, '')
AttributeError: 'unicode' object has no attribute 'get'


Thank you
parse_workitem.py
sample.txt
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial