0

Below json we are getting in response, and to this api we need to add new element for all input parameter array and send new request to server.

How to push "inputList":[ ] element below all array elements of inputParameters?

Response:

{
   "canBeSubscribed":false,
   "inputParameters":[
      {
         "allowBlank":false,
         "canBeShownOnUi":false,
         "uiControl":"1"
      },
      {
         "allowBlank":false,
         "uiControl":"1"
      }
   ],
   "reportTitle":"Report"
}

New Request:

{
   "canBeSubscribed":false,
   "inputParameters":[
      {
         "allowBlank":false,
         "canBeShownOnUi":false,
         "uiControl":"1",
         "inputList":[
            
         ]
      },
      {
         "allowBlank":false,
         "uiControl":"1",
         "inputList":[
            
         ]
      }
   ],
   "reportTitle":"Report_New"
}
Hgrbz
  • 185
  • 3
  • 12
  • 1
    JSON is a *textual notation* for data exchange. [(More here.)](http://stackoverflow.com/a/2904181/157247) If you're dealing with JavaScript source code, and not dealing with a *string*, you're not dealing with JSON. – T.J. Crowder Apr 07 '22 at 11:25

1 Answers1

1

const response = {
   "canBeSubscribed":false,
   "inputParameters":[
      {
         "allowBlank":false,
         "canBeShownOnUi":false,
         "uiControl":"1"
      },
      {
         "allowBlank":false,
         "uiControl":"1"
      }
   ],
   "reportTitle":"Report"
}

const newRequest = {
  ...response,
  reportTitle: "Report_New",
  inputParameters: response.inputParameters.map((inputParameter) => ({
    ...inputParameter,
    inputList: [],
  }))
}

console.log(newRequest);
Bad Dobby
  • 811
  • 2
  • 8
  • 22