title: Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse (<anonymous>) at Response.Body.json
body: <p>I am working on an angular2 project. I am stuck with these errors. The error occured when I tried to send the JSON objects to the backend. It may be due the parsing of JSON objects. I am new to angualar, so please do help</p>
  
  <p>Signup.service.ts</p>
  
  <pre><code>import {Injectable} from '@angular/core'; 
  import {Http, Headers} from '@angular/http';
  import 'rxjs/add/operator/map' ;
  @Injectable()
      export class SignupService{
          constructor (private http: Http){}  
          insertform(newreg: any ){
              console.log();
              var headers = new Headers ();
              headers.append('Content-Type','application/json');
              return this.http.post('http://localhost:3000/api/users', JSON.stringify(newreg),{headers: headers})
              .map(res=&gt; res.json());
           }
       } 
  </code></pre>
  
  <p>signup.component.ts </p>
  
  <pre><code>import { Component, AfterViewInit } from '@angular/core';
  import {SignupService} from '../../services/signup.service';
  import {Signup} from '../../../signup';
  declare var $: any;
   @Component({
   moduleId: module.id,
   selector: 'signup',
   templateUrl: 'signup.component.html',
    providers: [SignupService]
   })
   export class SignupComponent {
   datas: Signup[];
   data: any;
   first_name: string;
   last_name: string;
   address: string;
   email: string;
   pwd:string;
   pwdcnf:string;
   phone:number;
   constructor(private signupService: SignupService){ };
   ngAfterViewInit() {
      $('#textarea1').trigger('autoresize');
     };
       regformSubmit(event: any){
      event.preventDefault(); 
      var newreg = {
       first_name: this.first_name,
        last_name: this.last_name,
       email: this.email,
       address: this.address,
       phone: this.phone,
      pwd:this.pwd,
      pwdcnf:this.pwdcnf
     };
      this.signupService.insertform(newreg)
        .subscribe (data =&gt; {
         this.datas.push(data);
          this.first_name='';
           this.last_name ='';
           this.email='';
          this.address='';
           this.phone=0;
      this.pwd='';
      this.pwdcnf='';
        });     
    } 
   }
  </code></pre>
  
  <p>signup.component.html</p>
  
  <pre><code> &lt;div class="container light-blue lighten-5"&gt;
  &lt;form class="col s12" (ngSubmit)="regformSubmit($event)"&gt;
    &lt;div class="row"&gt;
      &lt;div class="input-field col s6"&gt;
        &lt;input  id="first_name" type="text" class="validate" [(ngModel)]="first_name" name="first_name" required&gt;
        &lt;label for="first_name"&gt;First Name&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="input-field col s6"&gt;
        &lt;input id="last_name" type="text" class="validate" [(ngModel)]="last_name" name="last_name" required&gt;
        &lt;label for="last_name"&gt;Last Name&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="row"&gt;
      &lt;div class="input-field col s12"&gt;
        &lt;textarea id="textarea1" class="materialize-textarea" [(ngModel)]="address" name="address" required&gt;&lt;/textarea&gt;
        &lt;label for="disabled"&gt;Address&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="row "&gt;
      &lt;div class="input-field col s5"&gt;
        &lt;input id="password" type="password" class="validate" [(ngModel)]="pwd" name="pwd" required&gt;
        &lt;label for="password"&gt;Password&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="input-field col s5 offset-s2"&gt;
        &lt;input id="password1" type="password" class="validate" [(ngModel)]="pwdcnf" name="pwdcnf" required&gt;
        &lt;label for="password1"&gt;Confirm password&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="row"&gt;
      &lt;div class="input-field col s5"&gt;
        &lt;input id="email" type="email" class="validate" [(ngModel)]="email" name="email" required&gt;
        &lt;label for="email"&gt;Email&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="input-field col s5 offset-s2"&gt;
        &lt;input id="password2" type="number" class="validate" [(ngModel)]="phone" name="number" required&gt;
        &lt;label for="password2"&gt;Phone&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
   &lt;div class="row"&gt;
       &lt;div class="input-field col s4 offset-s5"&gt;
           &lt;button class="btn waves-effect waves-light" type="submit" name="action"&gt;Submit
              &lt;i class="material-icons right"&gt;send&lt;/i&gt;
          &lt;/button&gt;
        &lt;/div&gt;
   &lt;/div&gt;
  &lt;/form&gt;
   &lt;/div&gt;
   &lt;style&gt;
    .ng-invalid {
     border-bottom-color: red;
    }
  &lt;/style&gt;
  </code></pre>
  
  <p>The full error message is</p>
  
  <pre><code>EXCEPTION: Unexpected token U in JSON at position 0
  ORIGINAL STACKTRACE:
  yntaxError: Unexpected token U in JSON at position 0
  at JSON.parse (&lt;anonymous&gt;)
  at Response.Body.json (http.umd.js:777)
  at MapSubscriber.eval [as project] (signup.service.ts:13)
  at MapSubscriber._next (map.ts:75)
  at MapSubscriber.Subscriber.next (Subscriber.ts:95)
  at XMLHttpRequest.onLoad (http.umd.js:1180)
  at ZoneDelegate.invokeTask (zone.js:275)
  at Object.onInvokeTask (core.umd.js:3971)
  at ZoneDelegate.invokeTask (zone.js:274)
  at Zone.runTask (zone.js:151)
  at XMLHttpRequest.ZoneTask.invoke (zone.js:345)
  Uncaught SyntaxError: Unexpected token U in JSON at position 0
  at JSON.parse (&lt;anonymous&gt;)
  at Response.Body.json (http.umd.js:777)
  at MapSubscriber.eval [as project] (signup.service.ts:13)
  at MapSubscriber._next (map.ts:75)
  at MapSubscriber.Subscriber.next (Subscriber.ts:95)
  at XMLHttpRequest.onLoad (http.umd.js:1180)
  at ZoneDelegate.invokeTask (zone.js:275)
  at Object.onInvokeTask (core.umd.js:3971)
  at ZoneDelegate.invokeTask (zone.js:274)
  at Zone.runTask (zone.js:151)
  at XMLHttpRequest.ZoneTask.invoke (zone.js:345)
  </code></pre>