JSON Object to CSV file

Denis McMahon denismfmcmahon at gmail.com
Sun Jun 21 16:52:57 EDT 2015


On Sun, 21 Jun 2015 06:57:01 -0700, sahluwalia wrote:

> On Sunday, 21 June 2015 02:47:31 UTC-4, Denis McMahon  wrote:
>> On Wed, 17 Jun 2015 08:00:11 -0700, Saran A wrote:
>> 
>> > I would like to have this JSON object written out to a CSV file so
>> > that the keys are header fields (for each of the columns) and the
>> > values are values that are associated with each header field.
>> 
>> > {
>> > "CF": {
>> .......
>> > "CF": "Fee",
>> 
>> Your json object seems to have the same key used for two elements at
>> the same level, are you sure this is legal json?

> I converted this from an XML file given to me from a third party. It is
> as is. I am not sure what you mean by "valid"; that is a very subjective
> measure for any form of quantitative or qualitative data.

Put it this way, when I feed your json object into a jason lint, the 
output is the following:

{
    "CF": "Fee",
    "ID": "2"
}

The second occurrence in the parent object of name "CF" with a value of 
string literal "Fee" overwrites the earlier name "CF" whose value is (in 
python terms) a dictionary or (in json terms) an object.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list