import pandas as pd
df=pd.read_json("student.json")
print(df)
Output is here
class id mark name sex
0 Four 1 75 John Deo female
1 Three 2 85 Max Ruin male
2 Three 3 55 Arnold male
3 Four 4 60 Krish Star female
4 Four 5 60 John Mike female
------------
------------
import pandas as pd
df=pd.read_json("https://www.plus2net.com/php_tutorial/student.json")
print(df)
It can be your localhost also.
import pandas as pd
df=pd.read_json("http://127.0.0.1/student.json")
print(df)
df=pd.DataFrame(data=my_dict)
df_j=df.to_json(orient='split')
print(df_j)
Output is here
{"columns":["NAME","ID","MATH","ENGLISH"],"index":[0,1,2],"data":[["Alex",1,50,50],["Ravi",2,36,48],["Ron",3,45,49]]}
To read the above JSON format, we have to maintain the same orient value as option.
df=pd.read_json(df_j,orient='split')
print(df)
[{"NAME":"Alex","ID":1,"MATH":50,"ENGLISH":50},{"NAME":"Ravi","ID":2,"MATH":36,"ENGLISH":48},{"NAME":"Ron","ID":3,"MATH":45,"ENGLISH":49}]
df=pd.read_json(df_j,orient='records')
{"0":{"NAME":"Alex","ID":1,"MATH":50,"ENGLISH":50},"1":{"NAME":"Ravi","ID":2,"MATH":36,"ENGLISH":48},"2":{"NAME":"Ron","ID":3,"MATH":45,"ENGLISH":49}}
df=pd.read_json(df_j,orient='index')
{"NAME":{"0":"Alex","1":"Ravi","2":"Ron"},"ID":{"0":1,"1":2,"2":3},"MATH":{"0":50,"1":36,"2":45},"ENGLISH":{"0":50,"1":48,"2":49}}
df=pd.read_json(df_j,orient='index')
[["Alex",1,50,50],["Ravi",2,36,48],["Ron",3,45,49]]
df=pd.read_json(df_j,orient='values')
df=pd.read_json("https://www.plus2net.com/php_tutorial/student2.json",lines=True)
Here if we use lines=False
then we will get error message. read_json()
function in Pandas?read_json()
function to read JSON data into a Pandas DataFrame?read_json()
function handle JSON files with complex nested structures?orient
parameter in the read_json()
function?orient
parameter affect the structure of the resulting DataFrame?read_json()
function read JSON data from a remote URL?lines
parameter work in the read_json()
function?read_json()
function?read_json()
function handle missing or NaN values in the JSON data?convert_axes
parameter affect the orientation of the resulting DataFrame when using the read_json()
function?Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.