import json

def filter_pokemon_data(input_file, output_file):
    try:
        # Load the dataset from the file
        with open(input_file, 'r', encoding='utf-8') as file:
            full_dataset = json.load(file)

        # Extract the first 300 Pokémon with the desired fields
        filtered_dataset = []
        for move in full_dataset:
            filtered_entry = {
                "name": move["name"],
                "type": move["type"],
                "power": move["power"],
                "category": move["category"],
            }
            filtered_dataset.append(filtered_entry)

        # Save the filtered dataset to a new file
        with open(output_file, 'w', encoding='utf-8') as file:
            json.dump(filtered_dataset, file, indent=4)
        
        print(f"Filtered dataset saved to {output_file}")

    except FileNotFoundError:
        print(f"File not found: {input_file}")
    except KeyError as e:
        print(f"Key error in processing: {e}")
    except Exception as e:
        print(f"An error occurred: {e}")

# Specify the input and output file paths
input_file_path = './moves.json'  # Replace with your file path
output_file_path = './movesOUT.json'  # Replace with your desired output path

# Call the function
filter_pokemon_data(input_file_path, output_file_path)
