title: JSON format for a dictionary with Pandas Dataframe as values
body: <p>I need to return, from a web framework (Flask for instance), a few dataframes and a string in a single Json object. My code looks something like this:</p>
  
  <pre><code>import pandas as pd
  data1 = [['Alex',10],['Bob',12],['Clarke',13]]
  df1 = pd.DataFrame(data1,columns=['Name','Age'])
  data2 = [['Cycle',5],['Run',1],['Hike',7]]
  df2 = pd.DataFrame(data1,columns=['Sport','Duration'])
  
  test_value={}
  test_value["df1"] = df1.to_json(orient='records')
  test_value["df2"] = df2.to_json(orient='records')
  print(json.dumps(test_value))
  </code></pre>
  
  <p>This outputs :</p>
  
  <pre><code>{"df1": "[{\"Name\":\"Alex\",\"Age\":10},{\"Name\":\"Bob\",\"Age\":12},{\"Name\":\"Clarke\",\"Age\":13}]", "df2": "[{\"Sport\":\"Alex\",\"Duration\":10},{\"Sport\":\"Bob\",\"Duration\":12},{\"Sport\":\"Clarke\",\"Duration\":13}]"}
  </code></pre>
  
  <p>So a number of escape characters in front of every key of the value of "df1" and "df2". If on the other hand, I look at <code>test_value</code>, I get:</p>
  
  <pre><code>{'df1': '[{"Name":"Alex","Age":10},{"Name":"Bob","Age":12},{"Name":"Clarke","Age":13}]', 'df2': '[{"Sport":"Alex","Duration":10},{"Sport":"Bob","Duration":12},{"Sport":"Clarke","Duration":13}]'}
  </code></pre>
  
  <p>Which is not quite right. What I need is 'df1' to be in double quotes "df1". Short of doing a search and replace in the string, what is the way to achieve that? </p>
  
  <p>I've even tried to create the string myself,  doing something like that :</p>
  
  <pre><code>print('\{"test": "{0:.2f}"\}'.format(123))
  </code></pre>
  
  <p>but I get this error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  KeyError                                  Traceback (most recent call last)
  &lt;ipython-input-266-1fa35152436c&gt; in &lt;module&gt;
  ----&gt; 1 print('\{"test": "{0:.2f}"\}'.format(123))
  
  KeyError: '"test"'
  </code></pre>
  
  <p>which I really don't get :). That said, there must be a better way then searching/replacing for the 'df1' for "df1".</p>
  
  <p>Ideas?</p>