title: HTTP POST - Json
body: <p>I am trying to post my json values in the nested format as  below but in my code, my data is submitted singly which is a constraint in the database. I select a number of doctors from my phone app and when i click save, the httpRequest much submit all the doctors selected singly as in the nested format. How can i submit the data in the nested format?</p>
  
  <p><strong>my code</strong></p>
  
  <pre><code>Hospitals = {
    hospital : "New York hospital",
    doctor: {
       details: {  
        id: "",
        ward: ""          
       }
    }
  }
  
  //this is how i post to the server 
   saveDoctorsForHospitals(){   
      Object.keys(this.Doctors).filter(key =&gt; this.Doctors[key].find)
         .forEach(key =&gt; {
             this.Hospitals.Doctors.details.id = this.Docotrs[key].id
             this.Hospitals.Doctors.details.ward = this.Doctors[key].ward
  
      this.httpService.submitAll(this.Hospitals)
          .subscribe(data =&gt; {
             console.log(data);   
          })
  </code></pre>
  
  <p><strong>this is how my data is submitted now</strong></p>
  
  <pre><code>  object 1         
      "hospital" : "McJames",
      "Doctor" : {
         "1" : {
            "id": 1269,
            "ward": "Demarco",                    
         }        
    Object 2
       "hospital" : "McJames",
       "Doctor" : {
          "2" : {
             "id": 1269,
             "ward": "Demarco",     
          }
  
  
  //but i want to be this 
  
      {
        "hospital" : "McJames",
        "Doctor" : {
           "1" : {
             "id": 1269,
              "ward": "Demarco",    
           },
  
           "2" : {
              "id": 1275,
              "ward": "Eden",
            }
          }
        }
  </code></pre>
  
  <p><strong>updated - wrapping in array</strong></p>
  
  <pre><code>Hospitals = {
    hospital : "New York hospital",
    doctor: [{
       details: {  
        id: "",
        ward: ""          
       }
    }]
  }
  </code></pre>