Skip to content

Structured data array output causes Safari browser error; use @graph object notation #618

@dkd-garip

Description

@dkd-garip
  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

The current implementation of Yoast SEO for TYPO3 outputs structured data as a JSON array inside the <script type="application/ld+json"> block, like this:

[
  { "@context": "https://schema.org", ... },
  { "@context": "https://schema.org", ... }
]

While this technically works, the JSON-LD specification and Google's documentation recommend publishing multiple objects within a single object using the @graph property and a single @context

The code responsible for this output can be found here:

Classes/StructuredData/StructuredDataProviderManager.php
Function: buildJsonLdBlob()

Please describe what you expected to happen and why.

Structured data to be output as a single object using the recommended @graph format, like this:

{
  "@context": "https://schema.org",
  "@graph": [
    { ... },
    { ... }
  ]
}

How can we reproduce this behavior?

  1. Install and activate the Yoast SEO for TYPO3 extension.
  2. Visit any frontend page that outputs structured data.
  3. Inspect the HTML source and locate the <script type="application/ld+json"> tag.
  4. Observe that the content is a JSON array, and not an object with @graph.

Screenshots

Logs

Additional context

When custom JavaScript tries to access the structured data in Safari browsers, a JavaScript error occurs due to the unexpected array format:
TypeError: undefined is not an object (evaluating 'r["@context"].toLowerCase')

Technical info

  • TYPO3 version: 13.4
  • Yoast SEO version: 11.0.2
  • Relevant extensions in case of a bug: none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions