I am new to python.
I have two set of JSON output files and I need to convert them to csv or dataframe.
File 1
{
"lastFileTime" : "2020-06-08T00:23:05.986-07:00",
"lastFileTimeMs" : "1591600985986",
"statNames" : ["stat1", "stat2", "stat3", "stat4", "stat5", "stat6", "stat7", "stat8", "stat9"],
"values" : [[1, 2, 3, 4, 5, 6, 7, 8, 9],[9, 8, 7, 6, 5, 4, 3, 2, 1]]
}
Desired Output
stat1,stat2,stat3,stat4,stat5,stat6,stat7,stat8,stat9
1,2,3,4,5,6,7,8,9
9,8,7,6,5,4,3,2,1
So I need to discard lastFileTime and lastFileTimeMs and read display in csv. I tried the following:
# Import the json module
import json
# Open a json file into a json object
with open('a.json') as F:
json_data = json.loads(F.read())
# Print loaded json object
print(json_data)
But I keep getting:
Traceback (most recent call last):
File "t.py", line 9, in <module>
json_data = json.loads(F.read())
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Any help is appreciated... The other problem I have is that I am tied to python 2.7.5 :(