I have developed an Angular 6 frontend application that uses Websockets to communicate with the backend server.
Upon sending a login request, the backend responds with a JSON object:
{"type":"LoggedIn","value":{"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a293e2938cc6c7">[email protected]</a>","id":9,"name":"1"}}
My challenge now is to extract and display specific fields from this JSON object.
Currently, I am able to see the entire backend message using the following function:
this.socketService.receiveEvents('LoggedIn').subscribe((message: MessageEvent) => {
console.log('message: ' + message.data);
});
The method "receiveEvents" aims for completeness:
/**
* TODO: Implement a parameter that filters relevant events for the calling functions
* @returns {Observable<Object>}
*/
receiveEvents(relevantEvent): Observable<Object> {
return this._subject.asObservable().pipe(filter((event: Event) => event != null));
}
How can I retrieve only certain fields like "type" or "value" from the JSON object?
I attempted iterating over it with a for loop, but encountered difficulties retrieving individual letters.
Any suggestions would be greatly appreciated. Thank you.