I need a json file in this order as i have to keep changing the json values. This is a sample file i want to generate
1.control_file Also the location name tag in the json should be enclosed in "","" format which i need help with.
{
"user": "dex",
"issue_no": "test_tkt",
"start_date": "2017-07-01",
"end_date": "2017-07-01",
"geo-ids": [627,438,360],
"location_names": [
"India.v1.2a_Final",
"China.v2.3a_setup",
"Hongkong.4a"
]
}
Below is the code i wrote. The expected output
import json
import os
filename = input("Enter the file name: ")
user = input("Enter the user name: ")
ticket = input("Enter the ticket id: ")
start_date = input("Enter the start date: ")
end_date = input("Enter the end date: ")
test_list=[]
input_list=input("enter the exp names: ")
exports = input_list.split(",")
for names in exports:
demo = test_list.append(names)
print(demo)
if not os.path.splitext(filename)[1]:
filename += ".txt"
with open(filename, 'w') as f:
json.dump({
"user": user,
"ticket": ticket,
"start_date": start_date,
"end_date" : end_date,
"location_names" : [demo]
}, f, indent=4)
print("JSON saved to file {}".format(os.path.abspath(filename)))
output i get
{
"user": "dex",
"ticket": "test_tkt",
"start_date": "2017-07-01",
"end_date": "2017-07-01",
"location_names": [
None
None
None
]
}
Output i want:
{
"user": "dex",
"issue_no": "test_tkt",
"start_date": "2017-07-01",
"end_date": "2017-07-01",
"location_names": [
"India.v1.2a_Final",
"China.v2.3a_setup",
"Hongkong.4a"
]
}