I need assistance with making an API POST call in Angular 8. The JSON object structure that needs to be sent should follow this format:
-{}JSON
-{}data
-[]exp
+{} 0
+{} 1
However, the data I am sending is currently in this format:
-[]JSON
+{} 0
+{} 1
Upon receiving two objects {}`0, {}1
in an array named receivedData
, I am storing the data like so in my TypeScript code:
this.changedData = this.receivedData;
this.postService.postMethod(this.headers, this.changedData)
The postService method looks like this:
postMethod(header, changedData): Observable<any[]> {
return this.http.post<any>(`the url here`, changedData, {headers: header, responseType: 'text' as 'json'})
.pipe(map(response => {
return response;
}))
}
My question is how can I send the data in the desired format? I want the JSON structure of changedDetails
to match the specified format with the same naming conventions such as: {}data and []exp
. How can I push the receivedData
objects into exp[]
, which can then be included in data{}
and ultimately pushed into changedDetails {}
.