How to read JSON file in Python



Hey All,
I want to read JSON file, can someone tell what is wrong in the below code:

import numpy as np
import pandas as pd
import zipfile
import json
from import json_normalize

JSON_COLUMNS = ['device', 'geoNetwork', 'totals', 'trafficSource']
df1 = pd.read_csv(zipfile.ZipFile('').open('t2.csv'), 
                     converters={column: json.loads for column in JSON_COLUMNS},dtype={'fullVisitorId': 'str'})
for column in JSON_COLUMNS:
        column_as_df = json_normalize(df1[column])
        column_as_df.columns = [f"{column}.{subcolumn}" for subcolumn in column_as_df.columns]
        df1 = df1.drop(column, axis=1).merge(column_as_df, right_index=True, left_index=True)


I suggest to first try to unzip the file and just use the default pandas JSON reader, if the file is already in JSON format.

import pandas as pd
DF = pd.read_json(‘Complete_file_name’)


Hey Akash,

Thank you for your response.
I tried:

 zf = zipfile.ZipFile('')
 DF = pd.read_json('train.csv'))

and i got :

ValueError: Expected object or value.

Actually due to large file size, i zipped the file and upload on cloud and i want to access the file.