import os
import json

# Iterate over all files in the current directory
for filename in os.listdir():
    # Process only JSON files ending with "_printing.json"
    if filename.endswith("_printing.json"):
        try:
            # Read the JSON file
            with open(filename, "r", encoding="utf-8") as file:
                data = json.load(file)

            # Ensure "result" exists and contains "id"
            if "result" in data and isinstance(data["result"], dict) and "id" in data["result"]:
                data["result"]["item"] = data["result"].pop("id")  # Rename "id" to "item"

                # Write the changes back to the file
                with open(filename, "w", encoding="utf-8") as file:
                    json.dump(data, file, indent=4)

                print(f"Updated {filename}")

        except Exception as e:
            print(f"Error processing {filename}: {e}")
