Untitled
unknown
plain_text
a year ago
968 B
8
Indexable
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):
rows = []
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)
for key, value in aws_data.items():
rows.append([key, value])
# Write to CSV
with open('output.csv', 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(["Key", "Value"])
csvwriter.writerows(rows)
# Replace 'your_directory_path' with the actual path to your directory
process_directory('your_directory_path')
Editor is loading...
Leave a Comment