import ujson as json
# Prepare dictionary with variables to save as json.
mydata = {'var1': 'Hello,',
'var2': 'World!'}
# Save data to file.
with open('datafile.json', 'w') as f:
json.dump(mydata, f)
# Read data from file.
with open('datafile.json', 'r') as f:
variables = json.load(f)
# Loaded data is a dict, so use it as one.
print(variables['var1'])
print(variables['var2'])