import json file_path = 'grafana/dashboards/dashboard.json' with open(file_path, 'r') as f: data = json.load(f) def fix_datasource(obj): if isinstance(obj, dict): if 'datasource' in obj and isinstance(obj['datasource'], dict): if obj['datasource'].get('type') == 'elasticsearch': obj['datasource'] = 'Elasticsearch' for key, value in obj.items(): fix_datasource(value) elif isinstance(obj, list): for item in obj: fix_datasource(item) fix_datasource(data) with open(file_path, 'w') as f: json.dump(data, f, indent=2)