How do i read the config files entries in angular 2?
<p>I need to read the config file which is in a json format. the json file contains config entries in key/pair values. How do I get the values of any particular key?</p>

<p>My question is, I can read the json file on a whole using http.get() or any other way, but how do i get a particular config value based on a key? should i need to loop thru/iterate the items to get the required item or is there any other better ways to do it?</p>

<p>my json config looks like below</p>

<pre><code>{
  "SecurityService": "http://localhost/SecurityAPI",
  "CacheService": "http://localhost/CacheServiceAPI"
}
</code></pre>

<p>I tried do the code changes as per your suggestion
The code to read the config data from the json file </p>

<pre><code>getConfiguration = (): Observable&lt;Response&gt; =&gt; {
        return this.http.get('config.json').map(res =&gt; res.json());
    }
</code></pre>

<p>following code to invoke the above method from the calling component and use the read config values</p>

<pre><code>this._ConfigurationService.getConfiguration()
            .subscribe(
            (res) =&gt; {
                this.configs = res;
                console.log(this.configs);
            },
            (error) =&gt; console.log("error : " + error),
            () =&gt; console.log('Error in GetApplication in Login : ' + Error)
        );
</code></pre>

<p>But when the above is getting executed, I am getting the error as </p>

<p><code>"error : SyntaxError: Unexpected token &lt; in JSON at position 0"</code></p>

<p>what is the mistake I am doing here, the same code to read the json file works in other scenarios where I need to read data from json and bind the grid etc.</p>

<p>I have tried reproducing the issue in plunkr <a href="https://plnkr.co/edit/rq9uIxcFJUlxSebO2Ihz?p=preview" rel="noreferrer">https://plnkr.co/edit/rq9uIxcFJUlxSebO2Ihz?p=preview</a></p>