rxjs: filter observable by json field
<p>I have a observable created based on websocket event.</p>

<pre><code>Observable.fromEvent&lt;Response&gt;(websocket, 'message');
</code></pre>

<p>it contains json objects like </p>

<pre><code>{"id": "A", "value": 123}
{"id": "B", "value": 456}
{"id": "C", "value": 789}
{"id": "A", "value": 321}
</code></pre>

<p>Now, I'm going to create three observables, events in each of them have same id. (Eg. observable 1 contains only events with <code>"id": "A"</code>) so that subscriber who only cares about <code>"id": "A"</code> can subscribe the specific one.</p>

<p>So, I created observable like</p>

<pre><code>public GetMonitorData = (): Observable&lt;Response&gt; =&gt; {
     Observable.fromEvent&lt;Response&gt;(websocket, 'message')
           .filter(function (result, idx) {
                return JSON.parse(result)['id'] === 'A'; //syntax error at here
            });
}
</code></pre>

<p>and subscribe like</p>

<pre><code>GetMonitorData().subscribe((result) =&gt; {
      // I expect all subscribed events at here are of same 'id'
      let parsedResponse = JSON.parse(result.data);
      this.updateStats(parsedResponse);
});
</code></pre>

<p>Edit: I expect I can filter based on the <code>'id'</code> of json objects, but <code>return JSON.parse(result)['id'] === 'A';</code> complains <code>Argument of type Response is not assignable to parameter of type string</code>. So, I don't know how to extract the <code>'id'</code> from Observable's event and use it to filter events.</p>

<p>Put it in another way, I have incoming observable like</p>

<pre><code>--A--B--A--C--B--C---&gt;
</code></pre>

<p>and I want to create three observables like</p>

<pre><code>--A--A--&gt;
--B--B--&gt;
--C--C--&gt;
</code></pre>

<p>where <code>A, B, C</code> are events whose JSON <code>'id'</code> value is <code>A, B, C</code>, respectively. I don't know how to filter based the <code>'id'</code> value, since the event is observable, <code>JSON.parse(result)['id']</code> can't extract it.</p>