old_contents: import json
  import csv
  
  def json_to_csv(json_file):
  	with open(json_file, 'r') as jsonfile, open('output.csv', 'w', newline='') as csvfile:
  		jsn = json.load(jsonfile)
  		fieldnames = []
  		for name in jsn[0]:
  			fieldnames += [name]
  		writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
  
  		writer.writeheader()
  		for elem in jsn:
  			writer.writerow(elem)
  
  def csv_to_json(csv_file):
  	with open(csv_file, 'r') as csvfile, open('output.json', 'w') as jsonfile:
  		reader = csv.DictReader(csvfile)
  		jsn = []
  		for row in reader:
  			jsn += [row]
  
  		json.dump(jsn, jsonfile)
  		
  filename = input('Enter filename of CSV file: ')
  csv_to_json(filename)
new_contents: import json
  import csv
  import argparse
  
  def json_to_csv(json_file):
  	with open(json_file, 'r') as jsonfile, open('output.csv', 'w', newline='') as csvfile:
  		jsn = json.load(jsonfile)
  		fieldnames = []
  		for name in jsn[0]:
  			fieldnames += [name]
  		writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
  
  		writer.writeheader()
  		for elem in jsn:
  			writer.writerow(elem)
  
  def csv_to_json(csv_file):
  	with open(csv_file, 'r') as csvfile, open('output.json', 'w') as jsonfile:
  		reader = csv.DictReader(csvfile)
  		jsn = []
  		for row in reader:
  			jsn += [row]
  
  		json.dump(jsn, jsonfile)
  
  def main():
  	parser = argparse.ArgumentParser()
  	parser.add_argument('inputtype', help='The type of input', type=str, choices=['csv', 'json'])
  	parser.add_argument('filename', help='Name of the input file', type=str)
  	args = parser.parse_args()
  
  	if (args.inputtype=='csv'):
  		csv_to_json(args.filename)
  		outputtype = 'json'
  	elif (args.inputtype=='json'):
  		json_to_csv(args.filename)
  		outputtype = 'csv'
  
  	print('[*] Output saved as output.{}'.format(outputtype))
  
  
  if __name__=='__main__':
  	main()
subject: Add command-line arguments and main function