import json # Load the JSON data from your file with open('discord_logs.json', 'r') as json_file: data = json.load(json_file) # Define the minimum values for filtering minimum_average_token_length = 125 # Set your desired minimum average token length minimum_median_token_length = 125 # Set your desired minimum median token length minimum_conversations_length = 6 # Set your desired minimum length of the 'conversations' array # Filter the items that meet the minimum criteria filtered_items = [ item for item in data if item.get('average_token_length', 0) >= minimum_average_token_length and item.get('median_token_length', 0) >= minimum_median_token_length and len(item.get('conversations', [])) >= minimum_conversations_length ] # Save the filtered items to a new JSON file with open(f'{minimum_median_token_length}_tokens_{minimum_conversations_length}_messages.json', 'w') as filtered_json_file: json.dump(filtered_items, filtered_json_file, indent=4) # Optionally, you can print the filtered items for i, item in enumerate(filtered_items): print(f"Filtered Item {i + 1} - Average Token Length: {item.get('average_token_length')}, Conversations Length: {len(item.get('conversations', []))}")