Convert json text file to csv file

import pandas as pd
import fire
import glob
import json

def text_to_csv(file_name):
    json_data = json.load(open(file_name, 'r'))
    df = pd.read_json(json_data)
    df.to_csv(file_name[:-3] + 'csv')

def main(dir):
    dir = dir.replace("\\", "/")
    file_paths = glob.glob(dir + "/*.txt")
    for fp in file_paths:
        print("file_path:" + fp)
        text_to_csv(fp)

if __name__ == ‘__main__’:
    fire.Fire()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325161272&siteId=291194637