import json
def extract_config(config_file):
"""
Extracts configuration values from a JSON file.
Args:
config_file (str): Path to the JSON configuration file.
Returns:
dict: A dictionary containing the configuration values.
Returns an empty dictionary if the file is not found or invalid.
"""
try:
with open(config_file, 'r') as f:
config = json.load(f) # Load JSON data
return config
except FileNotFoundError:
print(f"Error: Configuration file not found: {config_file}")
return {}
except json.JSONDecodeError:
print(f"Error: Invalid JSON format in {config_file}")
return {}
if __name__ == '__main__':
# Example usage: Replace 'config.json' with your actual config file
config_values = extract_config('config.json')
if config_values:
# Print the extracted configuration values (for testing)
print(json.dumps(config_values, indent=4))
Add your comment