I have Python script which retrieves data from an API in JSON format (at least I think its JSON format). I want to loop through each 'object' and write to a CSV file.
Here is the data returned from the api:
[
{
"bids_won": "7",
"partner_revenue": "$0.01",
"profit": "$0.00",
"campaign_id": "test 1",
"post_click_conversions": "0",
"total_cost": "$0.01",
"total_media_cost": "$0.01",
"post_view_conversions": "2",
"adjusted_partner_cost": "$0.01",
"clicks": "0",
"day": "August 21, 2011"
},
{
"bids_won": "30,209",
"partner_revenue": "$38.67",
"profit": "$8.92",
"campaign_id": "test 2",
"post_click_conversions": "0",
"total_cost": "$29.75",
"total_media_cost": "$29.75",
"post_view_conversions": "0",
"adjusted_partner_cost ": "$25.26",
"clicks": "10",
"day": "August 21, 2011"
}
]
How can I loop through these 'objects' and write them to a CSV file? My current attempt to loop through it results in the script interating through each letter..
Appreciate the help.
ps I'm using python 2.7