-
Notifications
You must be signed in to change notification settings - Fork 1
/
json-to-csv.py
25 lines (20 loc) · 871 Bytes
/
json-to-csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import csv
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("jsonFile", help="Filename of input JSON file")
parser.add_argument("csvFile", help="Filename of output CSV file")
parser.add_argument("os", help="Operating system - windows or linux")
args = parser.parse_args()
with open(args.jsonFile, 'r') as f:
input_json = json.load(f)
if args.os == "linux":
with open(args.csvFile, 'wb') as csvfile:
fieldnames = ['package', 'version']
csvwriter = csv.DictWriter(csvfile, fieldnames=fieldnames)
csvwriter.writeheader()
for package in input_json:
#print(package + " " + input_json[package][0]['version'])
csvwriter.writerow({'package': package, 'version':input_json[package][0]['version']})
main()