This script goes through a .json exported roam graph and converts the '/' characters in page titles with a '-' character.
Useful for Obsidian migration, because Obsidian interprets a file with the title '12/16 Math Notes' as a file called '16 Math Notes' in the folder '12/'.
import json
def replace_slashes(data):
if isinstance(data, dict):
for key, value in data.items():
if key == 'title' and isinstance(value, str):
data[key] = value.replace('/', '-')
else:
replace_slashes(value)
elif isinstance(data, list):
for item in data:
replace_slashes(item)
def process_json_file(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
replace_slashes(data)
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)
# Replace 'your_file.json' with the path to your JSON file
process_json_file('your_file.json')