I am creating a Python dictionary and the results contain a few thousand entries like this:
{
"stations": ".",
"Alt-Tagel": ".",
"id": 5718454109,
"name": "Alt-Tegel",
"label": "Alt-Tegel",
"position": ".",
"lat": 52.5894565,
"lon": 13.2837514
}
My program
import json
# Data to be written
def bus_line8():
keys = ['stations', 'Alt-Tegel', 'id', 'name', 'label', 'position' ,'lat', 'lon']
values = ['{', '{', 5718454109, 'Alt-Tegel', 'Alt-Tegel', '{' , 52.5894565, 13.2837514]
dictionary = dict(zip(keys, values))
print(dictionary) # {'a': 1, 'b': 2, 'c': 3}
# Serializing json
json_object = json.dumps(dictionary, indent = 4)
# Writing to sample.json
with open("bus_line.json", "w") as outfile:
outfile.write(json_object)
But I want this:
{
"stations": {
"Alt-Tegel": {
"id": 5718454109,
"name": "Alt-Tegel",
"label": "Alt-Tegel ",
"position": {
"lat": 52.5894565,
"lon": 13.2837514
}
Can someone help me please I'm on it since 2 days.