How does one do string formatting on nested dictionaries with triple quotes?
I have an api that I am hitting which requires my data
field to be formatted in a particular way.
values = """{
"profile": {
"census_tract": "41051003901",
"street_address": "123 N Fake Ave",
"city": "Portland",
"state": "OR",
"zip_code": "97203",
"lat": 45.0000,
"lon": -122.00000
}
}"""
I would like to do something along the lines of
{
"profile": {
"census_tract": "{0}",
"street_address": "{1}",
"city": "{2}",
"state": "{3}",
"zip_code": "{4}",
"lat": {5},
"lon": {6}
}
}
"""
print(values.format(in_census_tract, in_street_address, in_city, in_state, in_zip, in_lat, in_long))
Instead of the correctly formatted string, I get the following:
'\n "profile"'
The only thing that works is really ugly...
a = """
{
"profile": {"""
b = ''' "census_tract": "{0}",
"street_address": "{1}",
"city": "{2}",
"state": "{3}",
"zip_code": "{4}",
"lat": {5},
"lon": {6}
'''
c = """
}
}
"""
values = a + b.format(in_census_tract, in_street_address, in_city, in_state, in_zip, in_lat, in_long) + c