-
Notifications
You must be signed in to change notification settings - Fork 10
/
json2tsv.py
executable file
·41 lines (41 loc) · 1.09 KB
/
json2tsv.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import json
import csv
with open('data/data.json', 'r') as json_file:
json_data=json_file.read()
installations = json.loads(json_data)['installations']
with open('dataverse-installations.tsv', 'w', newline='') as tsvfile:
output = csv.writer(tsvfile, delimiter='\t')
header = [
'name',
'country',
'launch_year',
'hostname',
'continent',
'latitude',
'longitude',
'about_url',
'description',
]
output.writerow(header)
for i in installations:
name = i['name']
country = i['country']
launch_year = i.get('launch_year', None)
continent = i['continent']
hostname = i['hostname']
latitude = i['lat']
longitude = i['lng']
about_url = i.get('about_url', None)
description = i['description']
output.writerow([
name,
country,
launch_year,
hostname,
continent,
latitude,
longitude,
about_url,
description,
])