with open(output_file, 'r') as my_file:
    contents = my_file.read()
destination_file = contracts_dir + '/' + data['filename']
fp = open(destination_file, 'w')
for key, value in data.items():
    contents = contents.replace('$' + str(key), value)
fp.write(contents)
fp.close()
How to replace values from JSON with those found by RegEx in a file using Python?