JSON (JavaScript Object Notation) files are a widely used format for interchanging data among web applications and servers. It acts as a data interchanger and is more readable compared to XML. pandas offers the read_json function for reading JSON data and to_json() for writing JSON data:
# Reading JSON file
df=pd.read_json('employee.json')
# display initial 5 records
df.head()
This results in the following output:
In the preceding code example, we have read the JSON file using the read_json() method. Let's see how to write a JSON file:
# Writing DataFrame to JSON file
df.to_json('employee_demo.json',orient="columns")
In the preceding code example, we have written the JSON file using the to_json() method. In the to_json() method, the orient parameter is used to handle the output string format. orient offers record, column, index, and value kind of formats. You can explore it in more detail on the official web page, at...