Untitled
unknown
plain_text
a month ago
993 B
2
Indexable
Never
import os import json import csv def process_json_file(filepath): with open(filepath, 'r') as file: data = json.load(file) customer_data = data.get('customer', {}) aws_data = {k: v for k, v in customer_data.items() if "aws-co" in k} return aws_data def process_directory(directory): aws_keys = [] aws_values = [] for root, dirs, files in os.walk(directory): for file in files: if file.endswith('.json'): filepath = os.path.join(root, file) aws_data = process_json_file(filepath) aws_keys.extend(aws_data.keys()) aws_values.extend(aws_data.values()) # Write to CSV with open('output.csv', 'w', newline='') as csvfile: csvwriter = csv.writer(csvfile) csvwriter.writerow(aws_keys) csvwriter.writerow(aws_values) # Replace 'your_directory_path' with the actual path to your directory process_directory('your_directory_path')
Leave a Comment