REVISION OF MY INQUIRY
I possess a json file titled products.json which holds a collection of products along with their id, name, quantity, description, and image URLs associated with each product. Here is an illustration of the JSON file:
[
{
"id":1,
"name": "APPLE IPHONE 13 256GB",
"desc": "some description ...",
"price": 1599.0,
"qty": 15,
"imgUrls": "../Images/iphone-13"
},
{
"id":2,
"name": "GALAXY NOTE10",
"desc": "some description ...",
"price": 200.0,
"qty": 10,
"imgUrls": "../Images/galaxy"
},
{
"id":3,
"name": "APPLE IPHONE 12 128GB",
"desc": "some description ...",
"price": 1599.0,
"qty": 15,
"imgUrls": "../Images/iphone-12"
}
]
Furthermore, I have the Product object outlined below:
export class Product {
constructor(
public id: number,
public name: string,
public desc: string,
public price: number,
public qty: number,
public imgUrls: string[]
) {}
}
My objective is to establish an array of type Product, encompassing all the products imported from the json file.
Although I am aware that creating the products manually would resemble this:
products: Product[] = [
new Product(1,
"APPLE IPHONE 13 256GB",
"some description...",
1599.0,
15,
["../Images/iphone-13"]),
new Product(2,
"GALAXY NOTE10",
"some description...",
200.0,
10,
["../Images/galaxy"]),
new Product(3,
"APPLE IPHONE 12 128GB",
"some description ...",
1599.0,
15,
["../Images/iphone-12"])
];
My aspiration is to generate this object utilizing the json file.
I deeply appreciate your assistance.
If my explanation is unclear, please feel free to mention that in the comments so I can refine my inquiry.