Useful or not, from you.
angular HttpClient 'Http failure during parsing' error for valid json

<!-- PLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.

ISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION. -->

I'm submitting a...

<!-- Check one of the following options with "x" --> <pre><code> [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report <!-- Please search GitHub for a similar issue or PR before submitting --> [ ] Feature request [ ] Documentation issue or request [ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question </code></pre>

Current behavior

<!-- Describe how the issue manifests. --> Request throws an error when trying to parse a response of "ok" which is considered valid json according to https://jsonlint.com/


request:

    const requestOptions = Object.assign(
      {}, 
      { responseType: 'json' }, 
      { observe: 'body' as HttpObserve }
    );

    this.httpClient.request('GET', './mockjson.json', requestOptions)
    ...

error: "Unexpected token o in JSON at position 0"

Expected behavior

<!-- Describe what the desired behavior would be. --> No error should be thrown for a response of "ok"

Minimal reproduction of the problem with instructions

<!-- For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5). --> https://embed.plnkr.co/klPNUS/

What is the motivation / use case for changing the behavior?

<!-- Describe the motivation or the concrete use case. -->

Environment

<pre><code> Angular version: 4.3.2 <!-- Check whether this is still an issue in the most recent Angular version -->

Browser:

  • [x] Chrome (desktop) version XX
  • [ ] Chrome (Android) version XX
  • [ ] Chrome (iOS) version XX
  • [ ] Firefox version XX
  • [ ] Safari (desktop) version XX
  • [ ] Safari (iOS) version XX
  • [ ] IE version XX
  • [ ] Edge version XX

For Tooling issues:

  • Node version: XX <!-- run node --version -->
  • Platform: <!-- Mac, Linux, Windows -->

Others: <!-- Anything else relevant? Operating system version, IDE, package manager, HTTP server, ... --> </code></pre>

That's a useful answer
Without any help

Hi, It works for me to set Headers like let httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', }), responseType: 'text' as 'json' }; Hope it helps.