Sep-28-2017, 04:34 AM
(This post was last modified: Sep-28-2017, 04:38 AM by PythonNewbster.)
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
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