Im trying to parse this json file that has my store's products using php but with no luck! I'm new to php and I tried searching online but nothing had the answer. Here is part of my json file:
[
{
"_type": "default",
"description": [
"Product Description comes here"
],
"url": "here is the url to my seo friendly url",
"price": [
"11.64"
],
"sizes": [
"sizes come here"
],
"images": [
"image name and address is here"
],
"_template": "5c1333451e128f546e451197f6c6061b3a66d1ee",
"_cached_page_id": "5119b553b1512ae1a19d6cd0d3f29e51e111a90c",
"name": [
"product name is here"
]
},
{
"_type": "default",
"description": [
"Product #2 Description comes here"
],
"url": "here is the url to my seo friendly url",
"price": [
"11.64"
],
"sizes": [
"sizes come here"
],
"images": [
"image name and address is here"
],
"_template": "5c1333451e128f546e451197f6c6061b3a66d1ee",
"_cached_page_id": "5119b553b1512ae1a19d6cd0d3f29e51e111a90c",
"name": [
"product #2 name is here"
]
}
]
This is just a sample of the whole json file but it follows this format. I tried writing the following php code to index it but as I said, no luck:
<?php
// this code reads from the files provided to it and populates the database with products
$jsondata = file_get_contents("55products.json");
$json = json_decode($jsondata, true);
foreach ($json["products"] as $product)
{
// now lets split it into smaller pieces
foreach ($product as $product_infos) {
print_r($product_infos);
echo "<br /><br /><br />";
}
}
But still can't access the contents or to be specific, I don't know how to access the data store in there. I understand this might be a very stupid question but all the tutorials online don't have a similar syntax so please help me out. Best regards.