Home > Net >  how can i fill my key's json automatically
how can i fill my key's json automatically

Time:07-23

I have a json template that I would like to autofill.

currently i do it manually like this:
        for i in range(len(self.dict_trie_csv_infos)):
            self.template_json[i]['name'] = self.dict_trie_csv_infos[i]['name']
            self.template_json[i]['title'] = self.dict_trie_csv_infos[i]['title']
            self.template_json[i]['startDateTime'] = self.dict_trie_csv_infos[i]['startDateTime']
            self.template_json[i]['endDateTime'] = self.dict_trie_csv_infos[i]['endDateTime']
            self.template_json[i]['address'] = self.dict_trie_csv_infos[i]['address']
            self.template_json[i]['locationName'] = self.dict_trie_csv_infos[i]['locationName']
            self.template_json[i]['totalTicketsCount'] = self.dict_trie_csv_infos[i]
            .....etc..
                 

as you can see they have the same key's name, i tried to do it with a loop but it didn't worked.

How can i fill it automatically (is it possible)?

Thanks for your answer

CodePudding user response:

If you're matching names you could do something like:

for i in range(len(self.dict_trie_csv_infos)):
    for key in list(self.dict_trie_csv_infos.keys()):
            self.template_json[i][key] = self.dict_trie_csv_infos[i][key]
  • Related