This code returns a str as the type. Given the format of tasks, how do I convert it into a python dictionary?
import json
tasks = '''{'key1': 'val1', 'key2': None}'''
new_tasks = tasks.replace("'", "\"")
new_tasks = new_tasks.replace('None', 'null')
new_tasks = json.dumps(new_tasks)
new_tasks = json.loads(new_tasks)
print(type(new_tasks))
Note: I would prefer to not use ast.literal_eval or ast.eval.
json.dumps().ast.literal_eval()? This is precisely what it's intended for.{'None': 'val1'}or{'key1': 'None of us are coming'}jsonpackage. You have the right idea, but you need to learn the usage idioms.