I want to format json string with **dict like normal string, but here somthing wrong with my code, how to do to meet my requirements?
Here's my code:
varDict = {"age": 18, "gender": "male"}
jsonStringVar = """
{
"persion":
{
"age": "{age}",
"gender": "{gender}"
}
}
"""
print(jsonStringVar.format(**varDict))
And Exception as below:
Exception has occurred: KeyError
'\n "persion"'
File "..\test_format.py", line 43, in <module>
print(jsonStringVar.format(**varDict))