Search This Blog

Monday, February 28, 2022

Removing the Nesting object in to single object

 Iterating the array of objects and removing the nested object and adding in single object


Json Object:


  1. results[10]

    1. 0{

    2. hospital_details: { 

    3. site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", 
    4. city: "BENGALURU"

    5. }

    6. end_customer_details : {

      1. site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", 
      2. city: "BENGALURU"
    7. }

    8.   "toSalesOrder": "",
    9.   "toSalesOrderLineNumber": "", 
    10.   "toSalesOrderLineDetailedNumber": "",
    11.   "toInvoiceNumber": "",
      1. availableQuantity1
      2. cpNumber"3061392"
      3. created_on"2021-12-01T16:14:50.115995Z"


    12. }

  1. 1{

  2. hospital_details: { 

  3. site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", 
  4. city: "BENGALURU"

  5. }

  6. end_customer_details : {

    1. site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", 
    2. city: "BENGALURU"
  7. }

  8.   "toSalesOrder": "",
  9.   "toSalesOrderLineNumber": "", 
  10.   "toSalesOrderLineDetailedNumber": "",
  11.   "toInvoiceNumber": "",
    1. availableQuantity1
    2. cpNumber"3061392"
    3. created_on"2021-12-01T16:14:50.115995Z"

  12. }


Output:
  1. results[10]

    1. 0{
  1. end_customer_name"IGENETIC DIAGNOSTICS PVT LTD"
  2. end_customer_pincode"400072"
  3. end_customer_region"WEST"
  4. end_customer_site_id"46280291"
  5. end_customer_state"MAHARASHTRA"
  6. fromEndCustomerNumber"10195892"
  7. fromInvoiceNumber"17331148051"
  8. "toSalesOrder": "", "toSalesOrderLineNumber": "", "toSalesOrderLineDetailedNumber": "", "toInvoiceNumber": "", availableQuantity: 1 cpNumber: "3061392" created_on: "2021-12-01T16:14:50.115995Z"



}

 res['results'].forEach((element: any, index) => {

           let hospitaldetails = element.hospital_details;
           let customerdetails =   element.end_customer_details;
           let grid =  Object.assign(element, hospitaldetails, customerdetails);      
           this.gridData.push(grid);
        });    

No comments:

Post a Comment

Validating to select in sequencial order using angular

    < input type = "checkbox" (change) = "handleSelectTaskItem($event, taskItem)" [checked] = " taskItem . i...