JSON is a popular dictionary-like, key-value pair-based data structure that's suitable for exposing data as APIs from SaaS tools. address, postalCode, state, streetAddress, age, firstName, lastName, and phoneNumber are keys whose values are shown to the right of them. JSON files can be nested (the values of a key are JSON) as well. Here, address has nested values:
Example of JSON data (dictionary; key-value pairs)
DataFrames can be converted into JSON using to_json:
import numpy as np pd.DataFrame(np.random.randn(5, 2), columns=list('AB')).to_json() "
Take a look at the following screenshot:
Converting a DataFrame into JSON format
While converting the DataFrame into a JSON file, the orientation can be set.
If we want to keep the column name as the primary index and the row indices as the secondary index, then we can choose the orientation to be columns...