'Pandas read json ValueError: Protocol not known

I ran these codes a while ago and it worked but now there is a ValueError: protocol not known. Could anyone help. Thanks.

import json
temp = json.dumps([status._json for status in tweet]) #create JSON
newdf = pd.read_json(temp, orient='records')


Solution 1:[1]

As far as I could debug this issue is caused by an update of pandas. The 1.1.0 update had changed few things on the read_json function.

I could make my code work when setting pandas version to 1.0.5

https://pandas.pydata.org/docs/whatsnew/v1.1.0.html

Solution 2:[2]

The solution in my case consisted in using StringIO as below:

from io import StringIO
newdf = pd.read_json(StringIO(temp))

Looks like pd.read_json in Pandas 1.1 is no more accepting simple string.

Solution 3:[3]

I agree with ehabets

from io import StringIO
df = pd.read_json(StringIO(json_demo))

now, pd.read_json need the file type's json. That means pd.read_json("xxx.json") can work.

Solution 4:[4]

your code:

import json
temp = json.dumps([status._json for status in tweet]) #create JSON
newdf = pd.read_json(temp, orient='records')

Fix code:

import json
from io import StringIO
temp = StringIO(json.dumps([status._json for status in tweet])) #create JSON
df = pd.read_json(StringIO(temp, orient='records')

It work on pandas==1.1.3

Solution 5:[5]

For reference, another approach if the above fails:

Convert existing Excel file via Microsoft Excel to .XLSX format and save

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Henrique Brisola
Solution 2 ehabets
Solution 3 TophNanfong
Solution 4 rxtra
Solution 5 Fabian