Skip to content
Advertisement

Convert JSON Dict to Pandas Dataframe

I have what appears to be a very simple JSON dict I need to convert into a Pandas dataframe. The dict is being pulled in for me as a string which I have little control over.

{
  "data": "[{'key1':'value1'}]"
}

I have tried the usual methods such as pd.read_json() and json_normalize() etc but can’t seem to get it anywhere close. Has anyone a few different suggestions to try. I think ive see every error message python has at this stage.

Advertisement

Answer

It seems to me that your JSON data is improperly formatted. The double quotations around the brackets indicate that everything within those double quotes is a string. Essentially the data is considered a string and not an array of values. Remove the double quotes and to create an array in your JSON file.

{
  "data": [{"key1":"value1"}]
}

This will create the array and allow your JSON to be properly parsed using your previous stated methods.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement