Skip to content

Instantly share code, notes, and snippets.

@pekevski
Created September 22, 2021 03:27
Show Gist options
  • Save pekevski/02391e07a3fb67952bd2bbac4af51069 to your computer and use it in GitHub Desktop.
Save pekevski/02391e07a3fb67952bd2bbac4af51069 to your computer and use it in GitHub Desktop.
Convert a json file to csv in python
# pip install pandas
import pandas as pd
import sys
if len(sys.argv) is 2:
print(f'Error: 2 arguments required. Input file and output file. eg: to_csv.py file.json file.csv')
sys.exit()
input_file = sys.argv[1]
output_file = sys.argv[2]
print(f'Converting {input_file}...')
df = pd.read_json (input_file)
df.to_csv (output_file, index = None)
print(f'Success! Created {output_file}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment