# Convert json to dataframe in python

I have a json array f below format

[{
'Address': 'xxx',
'Latitude': 28. xxx,
'Longitude': 77. xxx,
'reached': False
}, {
'Address': 'yyy',
'Latitude': 18. yyy,
'Longitude': 73. yyy,
'reached': False
}]


i want to convert into dataframe. if the column name is same it should have (Address_0, Address_1 etc) and should be side by side, not below. How can i do this?

• Did you tried, what happens, what error shown? May 3, 2020 at 13:05

## 3 Answers

Have you tried using the pandas.read_json method? (documentation)

And it looks like your json is structured like 'records' so use

pd.read_json(_, orient='records')

• im getting error ValueError: Invalid file path or buffer object type: <class 'list'> May 3, 2020 at 13:15
• Did you change the underscore to the actual path? pd.read_json(PATH_HERE, orient='records') May 3, 2020 at 13:29
• The error you are getting is caused by the fact that the variable you are inputting (i.e. your data) is of type list, not a json string. May 3, 2020 at 13:32
• i have already read the input and parsed it. the above records are inside transit.. so what I have done is eachData['transits']=transitArray.. so above records are in transitarray.. so what should I do next? May 3, 2020 at 13:35
• Where are you getting your input data from and how are you parsing it? The issue is coming from the fact that your data is a list instead of a string. May 3, 2020 at 13:38

You can use the pd.DataFrame.from_records() method like:

pd.DataFrame.from_records(data)


Please use pd.json_normalize(data). It normalizes json structure into flat table of data:

data = [{
'Address': 'xxx',
'Latitude': 28.000,
'Longitude': 77.000,
'reached': False}, {
'Address': 'yyy',
'Latitude': 18.000,
'Longitude': 73.000,
'reached': False}]
pd.json_normalize(data)