I am trying to get an output similar to this.
{
"Continent": "Asia",
"Country": "Japan"
}
The code below is throwing an error.
var = "Japan"
message_body_3 = '{\n \"Continent\": \"Asia\",\n \"Country\": \"{0}\" \n} '.format(var)
Error:
message_body_3 = '{\n \"Continent\": \"Asia\",\n \"Country\": \" {0} \" \n} '.format(var)
KeyError: '\n "Continent"'
I want the {0} to be replaced with my variable.
What's the best way to achieve the result. I need to have backslashes and quotes in my string. Is there any way to do this in python ?