I'm trying to get a json file into csv format, here is a snippet of the json file(sample3.json) :
{
"x" : {
"-tst1" : {
"da" : "8C",
"d" : "df4",
"h" : 0,
"i" : 1,
"s" : false,
"t" : 1501394756245
},
"-tst2" : {
"da" : "8C",
"d" : "\\df&*",
"h" : 0,
"i" : 0,
"s" : true,
"t" : 1501394946296
}
}
}
These are some solutions that I've tried but I'm unabe to get any of them working: Convert list into a pandas data frame DataFrame from list of list Convert Nested JSON to Excel using Python
How can I get a table like the one below that I can export to a csv?
I've tried several different ways but I'm not getting anywhere...the furthest I've gotten is getting the values into a list.
It seems like it would be simple but I'm more of a sql guy not python.
I appreciate any help.
import json
import ast
import pandas as pd
from pprint import pprint
from pandas.io.json import json_normalize
import itertools
from openpyxl import load_workbook
import openpyxl
from collections import Counter
test = open('sample3.json').read()
data = json.loads(test)
vals = data['x']
for key in vals.keys():
v = vals.values
t = list(vals.values())
#pd.DataFrame(t)
#print(type(t))
#print('Separator')
#print(type(v))
df = pd.DataFrame.from_items(t) #error: Not enough values to unpack...expected 2, got 1.
print(df)