#sir i have no other ways, in nocode i
1 messages · Page 1 of 1 (latest)
import csv
import json
import argparse
def csv_to_json(csv_file_path, json_file_path):
jsonArray = []
#read csv file
with open(csv_file_path, encoding='utf-8') as csvf:
#load csv file data using csv library's dictionary reader
csvReader = csv.DictReader(csvf)
#convert each csv row into python dict
for row in csvReader:
#add this python dict to json array
jsonArray.append(row)
#convert python jsonArray to JSON String and write to file
with open(json_file_path, 'w', encoding='utf-8') as jsonf:
jsonString = json.dumps(jsonArray, indent=4)
jsonf.write(jsonString)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("csv_file", help="Path to the input CSV file.")
parser.add_argument("json_file", help="Path to the output JSON file.")
args = parser.parse_args()
i feel like there's a way simpler way to do this
will yes there's a one-liner awk