'Google Structured Data - Parsing error: Missing '}' or object member name
When I used Googles Rich Results page tester I keep running into an issue after injecting PHP into the javascript+td.
I am having a repeated error Parsing error: Missing '}' or object member name
<?php
$name = ucwords(strtolower($row['name']));
$city = ucwords(strtolower($row["city"]));
$state = $row["state"];
$profile_page_schema .= "
{
\"@type\": \"Person\",
\"name\": \"$name\",
\"jobTitle\": \"Insurance Agent\",
\"image\": \"https://<hidden>.com/assets/images/avatar.jpg\",
\"url\": \"https://<hidden>.com/pros/reviewinsurance.php?id=$id\",
\"worksFor\": {
\"@type\": \"Organization\",
\"name\": \"$name\",
\"url\": \"https://<hidden>.com/p/reviewinsurance.php?id=$id\",
\"address\": {
\"@type\": \"PostalAddress\",
\"addressLocality\": \"$city\",
\"addressRegion\": \"$state\",
\"addressCountry\": \"USA\",
}
}
";
$profile_page_schema = substr_replace($profile_page_schema ,"", -2);
echo
'<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "ProfilePage",
"mainEntity": ['.$profile_page_schema.']
}
</script>';
?>
Here is the rendered markup:
<!-- Google Structred Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "ProfilePage",
"mainEntity": [
{
"@type": "Person",
"name": "Kyle Riley Adams",
"jobTitle": "Insurance Agent",
"image": "https://<hidden>.com/assets/images/avatar.jpg",
"url": "https://<hidden>.com/pros/reviewinsurance.php?id=3549704",
"worksFor": {
"@type": "Organization",
"name": "Kyle Riley Adams",
"url": "https://<hidden>.com/pros/reviewinsurance.php?id=3549704",
"address": {
"@type": "PostalAddress",
"addressLocality": "Reno",
"addressRegion": "NV",
"addressCountry": "USA",
}
}
]
}
</script>
You can use the tool here https://search.google.com/test/rich-results
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
