I have a JSON file like this and have got troubles generating a table with COLUMNS as Name, number, countrycode(first item in price), currency
{"a": [{"Name": "name1",
"number": "number1",
"defaultPrice": {"p": "232", "currency": "CAD"},
"prices": {"DZ": {"p": "62", "currency": "RMB"},
"AU": {"p": "73", "currency": "AUD"},
"lg": "en"}},
{"Name": "name2",
"number": "number2",
"defaultPrice": {"p": "233", "currency": "CAD"},
"prices": {"DZ": {"p": "63", "currency": "RMB"},
"US": {"p": "72", "currency": "USD"},
"Lg": "en"}}]}
The problem is that I get traceback just at the parsing:
Traceback (most recent call last):
File "test.py", line 49, in <module>
val = ast.literal_eval(mystr)
File "/anaconda3/lib/python3.7/ast.py", line 46, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "/anaconda3/lib/python3.7/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 38
SyntaxError: unexpected EOF while parsing
What I used was
mystr='''
....
'''
val = ast.literal_eval(mystr)
val1 = json.loads(json.dumps(val))
val2 = val1['a'][0]['Name']
print pd.DataFrame(val2, columns=["Name"])
Thanks for any help!!