28 lines
871 B
Python
28 lines
871 B
Python
import os
|
|
import json
|
|
|
|
def transform_json_file(file_path):
|
|
with open(file_path, 'r') as file:
|
|
data = json.load(file)
|
|
|
|
# Transform the "key" section
|
|
if "key" in data:
|
|
transformed_key = {}
|
|
for k, v in data["key"].items():
|
|
transformed_key[k] = {"item": v}
|
|
data["key"] = transformed_key
|
|
|
|
# Write the modified data back to the file
|
|
with open(file_path, 'w') as file:
|
|
json.dump(data, file, indent=2)
|
|
|
|
def process_directory(directory):
|
|
for filename in os.listdir(directory):
|
|
if filename.endswith('.json'):
|
|
file_path = os.path.join(directory, filename)
|
|
transform_json_file(file_path)
|
|
print(f"Processed: {file_path}")
|
|
|
|
if __name__ == "__main__":
|
|
working_directory = os.getcwd() # Get the current working directory
|
|
process_directory(working_directory)
|