DS160123 not converting this file in json

import json

size = int(input(“enter employee no”))
data = {}
lst = []

for i in range(size):
data = {}
name = input(“Enter your name :”)
dob = (input(“Enter your dob :”))
height =(input(“Enter your height”))
city = input(“Enter your city name”)
state = input(“Enter your state name”)
data[“naam”] = name
data[“dob”]= dob
data[“height”] = height
data[“city”] = city
data[“state”] = state
lst.append(data)
with open(‘employee.json’, ‘w’) as file:
employee_json=json.dump(data, file)

3 Likes

What is the issue @sms18680

not getting output in json

1 Like

@sms18680
Try this

import json

size = int(input("Enter number of employees: "))
employee_data = []
for i in range(size):
data = {}
data[“name”] = input("Enter your name: ")
data[“dob”] = input("Enter your dob: ")
data[“height”] = input("Enter your height: ")
data[“city”] = input("Enter your city name: ")
data[“state”] = input("Enter your state name: ")
employee_data.append(data)

with open(“employee.json”, “w”) as file:
json.dump(employee_data, file)

Hope this will help :slightly_smiling_face:

3 Likes