How to convert an object to JSON correctly in Angular 2 with TypeScript
<p>I'm creating an Angular 2 simple CRUD application that allows me to CRUD products. I'm trying to implement the post method so I can create a product. My backend is an ASP.NET Web API. I'm having some trouble because when transforming my Product object to JSON it is not doing it correctly. The 
expected JSON should be like this:</p>

<pre><code>{
  "ID": 1,
  "Name": "Laptop",
  "Price": 2000
}
</code></pre>

<p>However, the JSON sent from my application is this:</p>

<pre><code>{  
   "product":{  
      "Name":"Laptop",
      "Price":2000
   }
}
</code></pre>

<p>Why is it adding a "product" in the beginning of the JSON? What can I do to fix this? My code:</p>

<p>product.ts</p>

<pre><code>export class Product {

    constructor(
        public ID: number,
        public Name: string,
        public Price: number
    ) { }   
}
</code></pre>

<p>product.service.ts</p>

<pre><code>import {Injectable}   from '@angular/core';
import {Http, Response} from '@angular/http';
import { Headers, RequestOptions } from '@angular/http';
import {Observable} from 'rxjs/Observable';

import {Product} from './product';

@Injectable()
export class ProductService {

    private productsUrl = 'http://localhost:58875/api/products';

    constructor(private http: Http) { }

    getProducts(): Observable&lt;Product[]&gt; {
        return this.http.get(this.productsUrl)
            .map((response: Response) =&gt; &lt;Product[]&gt;response.json())
            .catch(this.handleError);
    }

    addProduct(product: Product) {                
        let body = JSON.stringify({ product });            
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });

        return this.http.post(this.productsUrl, body, options)
            .map(this.extractData)
            .catch(this.handleError);
    }

    private extractData(res: Response) {
        let body = res.json();
        return body.data || {};
    }

    private handleError(error: Response) {
        console.error(error);
        return Observable.throw(error.json().error || 'Server Error');
    }
}
</code></pre>

<p>create-product.component.ts</p>

<pre><code>import { Component, OnInit }  from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';

import { Product } from '../product'
import { ProductService } from '../product.service'

@Component({
    moduleId: module.id,
    selector: 'app-create-product',
    templateUrl: 'create-product.html',
    styleUrls: ['create-product.css'],
})
export class CreateProductComponent {

    product = new Product(undefined, '', undefined);
    errorMessage: string;

    constructor(private productService: ProductService) { }

    addProduct() {            
        if (!this.product) { return; }
        this.productService.addProduct(this.product)
            .subscribe(
            product =&gt; this.product,
            error =&gt; this.errorMessage = &lt;any&gt;error);
    }
}
</code></pre>

<p>create-product.html</p>

<pre><code>&lt;div class="container"&gt;
    &lt;h1&gt;Create Product&lt;/h1&gt;
    &lt;form (ngSubmit)="addProduct()"&gt;
        &lt;div class="form-group"&gt;
            &lt;label for="name"&gt;Name&lt;/label&gt;
            &lt;input type="text" class="form-control" required [(ngModel)]="product.Name" name="Name"  #name="ngModel"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
            &lt;label for="Price"&gt;Price&lt;/label&gt;
            &lt;input type="text" class="form-control" required [(ngModel)]="product.Price" name="Price"&gt;
        &lt;/div&gt;
        &lt;button type="submit" class="btn btn-default" (click)="addProduct"&gt;Add Product&lt;/button&gt;
    &lt;/form&gt;
&lt;/div&gt;
</code></pre>