title: How to convert pandas dataframe to json
body: <p>I have json that looks like this:</p>
  <pre><code>{
      &quot;response&quot;: {
          &quot;docs&quot;: [{
                  &quot;region_s&quot; : &quot;North America&quot;,
                  &quot;country_s&quot;: &quot;Panama&quot;,
                  &quot;ArticleHeading_s&quot;: &quot;The expected vaccination process begins in Chiriquí&quot;,
                  &quot;ArticleDate_s&quot;: &quot;Fri Jun 18 17:29:07 UTC 2021&quot;,
                  &quot;refined_summary_t&quot;: &quot;Este jueves 13 de mayo la Operación PanavaC-19 inició el proceso de inmunización a los adultos mayores de 60 &quot;,
                  &quot;id&quot;: &quot;http://www.minsa.gob.pa/noticia/arranca-esperado-proceso-de-vacunacion-en-chiriqui&quot;,
                  &quot;source_type_s&quot;: &quot;Guidances/Regulations&quot;,
                  &quot;curation_date_t&quot;:&quot;12 Jun 2021 to 28 Jun 2021&quot;
              },
              {
                  &quot;region_s&quot; : &quot;North America&quot;,
                  &quot;country_s&quot;: &quot;US&quot;,
                  &quot;ArticleHeading_s&quot;: &quot;Emergency Use Authorization for Vaccines to Prevent COVID-19: Guidance for Industry&quot;,
                  &quot;ArticleDate_s&quot;: &quot;Fri Jun 15 17:29:07 UTC 2021&quot;,
                  &quot;refined_summary_t&quot;: &quot;&lt;ol&gt;&lt;li&gt; first list&lt;/li&gt; Second&lt;/li&gt;&lt;/ol&gt;&quot;,
                  &quot;id&quot;: &quot;http://www.minsa.gob.pa/noticia/arranca-esperado-proceso-de-vacunacion-en-chiriqui&quot;,
                  &quot;source_type_s&quot;: &quot;Press Releases/News&quot;,
                  &quot;curation_date_t&quot;:&quot;12 Jun 2021 to 18 Jun 2021&quot;
              }]
  </code></pre>
  <p>I convert it into pandas frame append some data and then need to convert it back to json. My final df looks something like this
  <a href="https://i.stack.imgur.com/tlvTI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tlvTI.png" alt="enter image description here" /></a></p>
  <p>I want to be able to convert it back to json. This is what the code looks like</p>
  <pre><code>out = {&quot;response&quot; : {&quot;docs&quot; : {[]} }}
  out[&quot;response&quot;][&quot;docs&quot;].append(df.to_json(orient='records')[1:-1].replace(&quot;'{&quot;,&quot;{&quot; ))
  print(out)
  with open('file_name.json', 'w') as f:
      f.write(out)
  </code></pre>
  <p>Unfortunately, it gives out an error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\fatima.arshad\PycharmProjects\pythonProject\main.py&quot;, line 42, in &lt;module&gt;
      out = {&quot;response&quot; : {&quot;docs&quot; : {[]} }}
  TypeError: unhashable type: 'list'
  </code></pre>