Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(maybe) JSON to CSV
#1
Hello All,

I am an ABSOLUTE beginner and I am about to ramp things up by taking the MIT Open Courseware course. I also have "Python Crash Course" at the ready. I have some Unix command-line skills and I have cobbled together some very ugly Perl scripts in the past. However, I am in a bind at the moment. I've searched all over the web for some examples that address my situation and some come close but not close enough.

I have, what is supposed to be JSON output, in a file that I need to loop through and print out to csv. There are some values in epoch time that I'd like to convert while I am at it. So, it seems that using the json library and getting these values in to a dictionary would be perfect. In my hands any library might as well be an ashtray. I am too embarrassed to even offer up what I have to this point.

The file essentially looks like this...
[
{
"primaryAdmin": "padmin",
"passwordExpiryDate": 1549837845656,
"loginName": "test1",
"loginLive": true,
"lastSetDate": 1486679445656,
"loginCat" : "TESTCAT",
"contactEmail": "test@test.com",
"genreName": "Trailblazer",
"secondaryAdmin": "sadmin",
"contactName": "Test Contact",
"lastLoginTime" : 1486765411722,
"peEnabled" : true,
},
{
"primaryAdmin": "padmin2",
"passwordExpiryDate": 1549837845656,
"loginName": "test2",
"loginLive": true,
"lastSetDate": 1486679445656,
"loginCat": "TESTCAT",
"contactEmail": "test2@test.com",
"genreName": "Trailblazer",
"secondaryAdmin": "sadmin2",
"contactName": "Test Contact2",
"lastLoginTime": 1486765411722,
"peEnabled" : true,
}
]

I don't know ANYTHING about JSON but from the examples I have seen, there is typically a string after that first open bracket. There is not in this case. It just jumps right in to the curly bracket. Is it possible that this makes it NOT-JSON?
At any rate, I just want to print all of the values from each line to file with the first line of output effectively being a header for all of the rows of just values underneath it. Converting the epoch values like "passwordExpiryDate","lastSetDate", and "lastLoginTime" would be gravy. I could just convert in excel but I might as well TRY to be elegant. ANY help here would be greatly appreciated.

-PythonNewbster
Reply


Messages In This Thread
(maybe) JSON to CSV - by PythonNewbster - Sep-28-2017, 04:34 AM
RE: (maybe) JSON to CSV - by buran - Sep-28-2017, 07:10 AM
RE: (maybe) JSON to CSV - by PythonNewbster - Sep-28-2017, 03:52 PM
RE: (maybe) JSON to CSV - by buran - Sep-28-2017, 04:08 PM
RE: (maybe) JSON to CSV - by PythonNewbster - Oct-03-2017, 07:44 PM
RE: (maybe) JSON to CSV - by nilamo - Oct-03-2017, 07:55 PM
RE: (maybe) JSON to CSV - by buran - Oct-03-2017, 08:01 PM
RE: (maybe) JSON to CSV - by PythonNewbster - Oct-03-2017, 09:18 PM
RE: (maybe) JSON to CSV - by nilamo - Oct-03-2017, 09:57 PM
RE: (maybe) JSON to CSV - by PythonNewbster - Oct-03-2017, 10:01 PM
RE: (maybe) JSON to CSV - by buran - Oct-03-2017, 10:59 PM
RE: (maybe) JSON to CSV - by PythonNewbster - Oct-04-2017, 04:44 AM
RE: (maybe) JSON to CSV - by buran - Oct-04-2017, 06:30 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020