title: How to use str.format inside a string of json format?
body: <p>Python Version 3.5</p>
  
  <p>I'm trying to make an API call to configure a device using json as the format. Some of the json will vary depending on the desired naming, so I need to call a variable in the string. I am able to accomplish this using the old style <code>%s... % (variable)</code>, but not with the new style <code>{}... .format(variable)</code>.</p>
  
  <p>Failed EX: </p>
  
  <pre><code>(Testing with {"fvAp":{"attributes":{"name":(variable)}}})
  
  a = "\"app-name\""
  
  app_config = ''' { "fvAp": { "attributes": { "name": {} }, "children": [ { "fvAEPg": { "attributes": { "name": "app" }, "children": [ { "fvRsBd": { "attributes": { "tnFvBDName": "default" }, } } ] } }, { "fvAEPg": { "attributes": { "name": "db" }, "children": [ { "fvRsBd": { "attributes": { "tnFvBDName": "default" }, } } ] } } ] } } '''.format(a)
  
  print(app_config)
  </code></pre>
  
  <blockquote>
    <p>Traceback (most recent call last): File "C:/..., line 49, in '''.format('a') KeyError: '\n "fvAp"'</p>
  </blockquote>
  
  <p>Working EX:</p>
  
  <pre><code>a = "\"app-name\""
  
  app_config = ''' { "fvAp": { "attributes": { "name": %s }, "children": [ { "fvAEPg": { "attributes": { "name": "app" }, "children": [ { "fvRsBd": { "attributes": { "tnFvBDName": "default" }, } } ] } }, { "fvAEPg": { "attributes": { "name": "db" }, "children": [ { "fvRsBd": { "attributes": { "tnFvBDName": "default" }, } } ] } } ] } } ''' % a
  
  print(app_config)
  </code></pre>
  
  <p>How do I get this to work using <code>str.format</code> method?</p>