Bug 255764 - Support of multiple contexts for JSON+LD content in script element (square brackets)
Summary: Support of multiple contexts for JSON+LD content in script element (square br...
Status: RESOLVED MOVED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL: https://w3c.github.io/json-ld-syntax/...
Keywords: BrowserCompat, CanvaBug, InRadar
Depends on:
Blocks:
 
Reported: 2023-04-20 20:37 PDT by Karl Dubost
Modified: 2024-06-04 00:05 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Dubost 2023-04-20 20:37:35 PDT
The advanced context usage for JSON+LD authorizes the use of an array.
https://w3c.github.io/json-ld-syntax/#advanced-context-usage

Nothing is said in the section about a restriction in embedding JSON+LD in html documents
https://w3c.github.io/json-ld-syntax/#embedding-json-ld-in-html-documents


So the square bracket syntax is failing in Safari:

```
data:text/html,%20%20%20%20<script%20type="application/ld+json">[{"@context":%20"https://schema.org"}]</script>
```

with 

```
TypeError: undefined is not an object (evaluating 'r["@context"].toLowerCase')
```

while this is working.

```
<script type="application/ld+json">{"@context": "https://schema.org"}</script>
```

The minimal test case to reproduce the issue is

```
<script type="application/ld+json">[]</script>
```


In both Chrome and Firefox, this syntax is accepted.
Comment 1 Radar WebKit Bug Importer 2023-04-20 20:37:50 PDT
<rdar://problem/108352610>
Comment 2 Karl Dubost 2023-12-15 01:21:02 PST
I have moved the radar to Safari, as this is not handled on WebKit side, but Safari side.
Comment 3 Xidorn Quan 2024-05-21 18:24:49 PDT
Karl, is there anywhere the progress of the issue can be tracked publicly?
Comment 4 Karl Dubost 2024-05-21 20:25:49 PDT
Oh yes I dropped the ball about that. 

So one side WebKit doesn't suport JSON+LD in the engine.
And the other Safari just needs the data as-is, so basically not to evaluate but just load it. 

Let see if there's an intermediary solution here.
Comment 5 Karl Dubost 2024-05-27 23:48:43 PDT
Xidorn, 
Do you know about an app or a current website with a usage for this construct/syntax?
Comment 6 Xidorn Quan 2024-05-28 04:43:28 PDT
Yes, Canva's logout templates page currently uses this syntax: https://www.canva.com/templates/ (If you have Canva account, you need to logout or use private mode to access).

I think we are fixing it, so I can't say how long it would keep being like it. Its current content is:
```
[{"@context":"https:\u002F\u002Fschema.org","@type":"WebSite","url":"https:\u002F\u002Fwww.canva.com\u002Ftemplates\u002F","potentialAction":[{"@type":"SearchAction","target":"https:\u002F\u002Fwww.canva.com\u002Ftemplates\u002Ftemplates\u002F?query={search_term_string}","query-input":"required name=search_term_string"}]}]
```
Comment 7 Karl Dubost 2024-05-28 14:24:54 PDT
Thanks a lot!
Comment 8 Karl Dubost 2024-06-04 00:05:48 PDT
Xidorn, this is still being discussed to find the origin of the issue and if it is something to fix on Safari side.
Comment 9 Karl Dubost 2024-06-04 00:05:55 PDT
Xidorn, this is still being discussed to find the origin of the issue and if it is something to fix on Safari side.