Created
July 29, 2025 21:30
-
-
Save JhonatanHern/73c12faa15020058b569b1c419978463 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import csv | |
# List of JSON log files to process | |
log_files = ['logs1.json', 'logs2.json', 'logs3.json', 'logs4.json'] | |
# Collect all logs | |
all_logs = [] | |
for file in log_files: | |
with open(file, 'r', encoding='utf-8') as f: | |
logs = json.load(f) | |
all_logs.extend(logs["logs"]) | |
# If there are logs, get the fieldnames from the first log | |
if all_logs: | |
fieldnames = all_logs[0].keys() | |
else: | |
fieldnames = [] | |
# Write to CSV | |
with open('logs.csv', 'w', newline='', encoding='utf-8') as csvfile: | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
writer.writeheader() | |
writer.writerows(all_logs) | |
print("Logs have been combined and written to logs.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment