Created
June 14, 2022 08:41
-
-
Save sukruozan/d924a83fec1c2c400bc0424c9e6e8324 to your computer and use it in GitHub Desktop.
This script converts an array stored as a JSON file to a CSV file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################# | |
#Script Name: json2csv.py | |
#Description: This script converts an array stored as a JSON file | |
# to a CSV file. | |
#Date : 14.06.2022 | |
#Author : Sukru Ozan | |
#Email : sukruozan@gmail.com | |
############################################################################# | |
import json | |
import sys | |
import numpy as np | |
import pandas as pd | |
def json2csv(json_file, csv_file): | |
""" | |
This function converts a JSON file to a CSV file. | |
:param json_file: The JSON file to convert. | |
:param csv_file: The CSV file to write to. | |
:return: None | |
""" | |
with open(json_file, 'r') as f: | |
data = json.load(f) | |
data = np.array(data) | |
df = pd.DataFrame(data) | |
df.to_csv(csv_file, index=False) | |
if __name__ == '__main__': | |
json2csv(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment