I have and array in JSON:
[
{
"ProductID": 1,
"ProductName": "Chai",
"SupplierID": 1,
"CategoryID": 1,
"QuantityPerUnit": "10 boxes x 20 bags",
"UnitPrice": 18,
"UnitsInStock": 39,
"UnitsOnOrder": 0,
"ReorderLevel": 10,
"Discontinued": false,
"Category": {
"CategoryID": 1,
"CategoryName": "Beverages",
"Description": "Soft drinks, coffees, teas, beers, and ales"
},
"FirstOrderedOn": new Date(1996, 8, 20)
},
...
]
I want to create array of objects:
export interface IProduct2{
ProductID: number,
ProductName: string
}
Attempt to get from HTTP file and parse:
products2$ = this.http.get<IProduct2[]>(this.product2Url)
.pipe(
map(products =>
products.map(product => ({
...product,
searchKey: [product.ProductName]
} as IProduct2))),
tap(data => console.log('Products 2: ', JSON.stringify(data))),
catchError(this.handleError)
);
Display in component:
<p>
{{products2$ | async | json}}
</p>
Error: "Server returned code: 200, error message is: Http failure during parsing for http://localhost:4200/api/products/products2.json"
So how to parse it properly into array of objects? How to properly display parsing success/errors, so I can figure out which part of JSON is causing issue? If it's a JSON file should be fine formatted.
Demo application with this issue is here: https://github.com/sam-klok/ang-http-data