Sep-15-2022, 02:32 PM
Hello all,
I'd like to ask your help to merge all json files in one folder after filtering data in each of them, name new file as "merged.json" in that folder.
Many results from various sports included in these json files. But I wanna have only football results together in merged.json file.
You ll see "ID":1 as dictionary of football results.
You can see two example json and desired "merged.json" in the below.
example1.json
I'd like to ask your help to merge all json files in one folder after filtering data in each of them, name new file as "merged.json" in that folder.
Many results from various sports included in these json files. But I wanna have only football results together in merged.json file.
You ll see "ID":1 as dictionary of football results.
You can see two example json and desired "merged.json" in the below.
example1.json
{ "results": [ { "Elems": [ { "Elems": [ { "ligName": "Premier League", "nameGame": "Chelsea - Liverpool", "score": "2-2" }, { "ligName": "Premier League", "nameGame": "Arsenal - Leeds", "score": "3-1" } ], "Name": "England. League Cup" }, { "Elems": [ { "ligName": "La Liga", "nameGame": "Barcelona - Valencia", "score": "2-0" } ], "Name": "La Liga" } ], "ID": 1 }, { "ID": 2 }, { "ID": 3 }, { "ID": 4 } ] }example2.json
{ "results": [ { "ID": 4 }, { "Elems": [ { "Elems": [ { "ligName": "Bundesliga", "nameGame": "Bayern - Dortmund", "score": "3-0" } ], "Name": "Bundesliga" }, { "Elems": [ { "ligName": "Ligue 1", "nameGame": "PSG - Monaco", "score": "4-0" } ], "Name": "Ligue 1" }, { "Elems": [ { "ligName": "Serie A", "nameGame": "Inter - Juventus", "score": "1-1" } ], "Name": "Serie A" } ], "ID": 1 }, { "ID": 3 }, { "ID": 2 } ] }merged.json
{ "results": [ { "Elems": [ { "Elems": [ { "ligName": "Premier League", "nameGame": "Chelsea - Liverpool", "score": "2-2" }, { "ligName": "Premier League", "nameGame": "Arsenal - Leeds", "score": "3-1" } ], "Name": "England. League Cup" }, { "Elems": [ { "ligName": "La Liga", "nameGame": "Barcelona - Valencia", "score": "2-0" } ], "Name": "La Liga" }, { "Elems": [ { "ligName": "Bundesliga", "nameGame": "Bayern - Dortmund", "score": "3-0" } ], "Name": "Bundesliga" }, { "Elems": [ { "ligName": "Ligue 1", "nameGame": "PSG - Monaco", "score": "4-0" } ], "Name": "Ligue 1" }, { "Elems": [ { "ligName": "Serie A", "nameGame": "Inter - Juventus", "score": "1-1" } ], "Name": "Serie A" } ] } ] }Note: I usually indicate encoding as "with open("example.json", encoding="UTF-8") as f:"