title: Converting pandas DataFrame rows a JSON schema and then making a POST Request
body: <h1>I have a dataset in JSON that looks like this:</h1>
  
  <pre><code>&gt;&gt;&gt; finalJSON
  '"company": {"name": "Micro inc.", "founders": {"name": "Jim D", "name": "Susan A"}, 
   "company": {"name": "Vitacore", "founders": {"name": "Billy B", "name": "Sally Q", "name": "Mark G"}'
  .....
  </code></pre>
  
  <h2>I need to loop through and send each of these items:</h2>
  
  <pre><code>'"company": {"name": "Micro inc.", "founders": {"name": "Jim D", "name": "Susan A"},
  </code></pre>
  
  <h2>to a POST Request like this:</h2>
  
  <pre><code>d = []
  for company in FinalJSON:
      p = requests.post((url + '/ratio'), json=company, headers=headers)
      if(p.status_code == 200):
              print p.text
              d.append(p.text)
      else:
              print(p.status_code)
              print "Error"
  </code></pre>
  
  <h2>Edit/Update</h2>
  
  <p>Hopefully this is a more complete example of what I'm exactly trying to do. I have a Pandas DataFrame that contains company names and employees like this:</p>
  
  <pre><code>&gt;&gt;&gt; print name_frame
  ... 
                 name    name    name    name        name
  Micro inc.      NaN    Jim D  Susan A      NaN       NaN
  Vitacore    Billy B      NaN  Sally Q   Mark G       NaN
  </code></pre>
  
  <p>What I need to do is convert this to a JSON format like this:</p>
  
  <pre><code>finalJSON = { 
      "company":{
          "name": "Micro inc.",
          "founders": {
              "name": "Jim D",
              "name": "Susan A",
              }
      }
      "company":{
          "name": "Vitacore",
          "founders": {
              "name": "Billy B",
              "name": "Sall Q", 
              "name":"Mark G",
          }
  </code></pre>
  
  <p>In a <a href="https://stackoverflow.com/questions/45088791/convert-json-data-from-pandas-to-a-specific-json-schema-format-in-python">previous question</a> I asked I was advised to try this out to get the desired JSON formate:</p>
  
  <pre><code>finalJSON = []
  for company, names in df.iterrows():
      names = ['"{0}"'.format(name) for name in names.dropna().tolist()]
      names_json_str = ('"name": ' if names else '') + ', "name": '.join(names)
      finalJSON.append('"company": {"name": "' + company + '", "founders": {' + names_json_str + '}')
  finalJSON = ', '.join(finalJSON)
  
  &gt;&gt;&gt; finalJSON
  '"company": {"name": "Micro inc.", "founders": {"name": "Jim D", "name": "Susan A"}, 
   "company": {"name": "Vitacore", "founders": {"name": "Billy B", "name": "Sally Q", "name": "Mark G"}'
  </code></pre>
  
  <p>So now I'm working with integrating the conversion with the post request: </p>
  
  <pre><code>for company, names in name_frame.iterrows():
      names = ['"{0}"'.format(name) for name in names.dropna().tolist()]
      names_json_str = ('"name": ' if names else '') + ', "name": '.join(names)
      payload = '"company": {"name": "' + company + '", "founders": {' + names_json_str + '}'
      p = requests.post((url), json=payload, headers=headers)
      if(p.status_code == 200):
              print p.text
              d.append(p.text)
      else:
              print(p.status_code)
              print "Error"
  </code></pre>
  
  <p>Though the payload is in fact not considered to be JSON serializable </p>
  
  <pre><code>TypeError: set([' + names_json_str + ']) is not JSON serializable
  </code></pre>