Sometimes you might want to generated JSON data dynamically. Below is the php code to achieve that . The $global variables are variables taken from the php page it self. For example you might have some variables stated in the top of the page and use those for the json generation script.

';
  $jsondata .= '{';
  $jsondata .= '"@context": "http://schema.org",';
  $jsondata .= '"@type": "NewsArticle",';
  $jsondata .= '"mainEntityOfPage": {';
  $jsondata .= '"@type": "WebPage",';
  $jsondata .= "\"@id\": \"{$page_url}\"";
  $jsondata .= '},';
  $jsondata .= "\"headline\": \"{$page_title}\",";
  $jsondata .= '"image": [';
    foreach ($str_data_images as $str_data_image) {
    $jsondata .= "$str_data_image,";
    }
  $jsondata = trim($jsondata,",");
  $jsondata .= '],';
  $jsondata .= "\"datePublished\": \"{$datePublished}\",";
  $jsondata .= "\"dateModified\": \"{$dateModified}\",";
  $jsondata .= '"author": {';
  $jsondata .= '"@type": "Person",';
  $jsondata .= "\"name\": \"{$siteName}\",";
  $jsondata .= "\"email\": \"mailto:admin@example.com\","; //your email address
  $jsondata .= "\"url\": \"https://example.com/contact/\""; // your contact page
  $jsondata .= '},';
  $jsondata .= '"publisher": {';
  $jsondata .= '"@type": "Organization",';
  $jsondata .= "\"name\": \"{$siteName}\",";
  $jsondata .= '"logo": {';
  $jsondata .= '"@type": "ImageObject",';
  $jsondata .= "\"url\": \"{$site_root}/static/images/logo.png\",";
  $jsondata .= '"width": "184",'; //your logo width
  $jsondata .= '"height": "60"'; // your lego height (must be 60px)
  $jsondata .= '}';
  $jsondata .= '},';
  $jsondata .= "\"description\": \"{$description}\"}";
  $jsondata .= '}';
  $jsondata .= '';
  return $jsondata;
}
echo structureddata();
?>