JSON-LD Created By Javascript Is Not Displayed In View-source

- 1 answer

There are 'duplicates' to my question but nobody answer my question :(

I am trying to generate JSON-LD structured data with javascript. Everything was fine until I checked from the tool, the JSON-LD code generated by javascript doesn't show up on the test table. When I proceed to view source on chrome it do not display the JSON-LD code.

You can see it live here

The code is below

<script id='myJSONID' type='application/ld+json'></script>
<script type='text/javascript'>
$('#myJSONID').text(function() {
    return JSON.stringify({
        "author": {
            "name":"Nhà đất Sơn Nghĩa",
        "itemReviewed": {
            "name": "" + document.title,
            "description":"" + document.getElementsByName("description")[0].content,
            "aggregateRating": {
                "@type": "AggregateRating",
                "ratingValue": "5",
                "bestRating": "5",
                "ratingCount": "20"

Does the above code have any problem? If not then how the JSON-LD code generated by javascript can be displayed when view-source (Ctrl + U)

Any suggestions are appreciated!

Thanks so much!



Because it shows only raw data and not exute Javascript in view-source, Try to use server side language to achieve this.