3

As far as I can see in the JSON-LD spec, section 3.1 - The Context, @context can either be:

  • an inline JSON object:

    { "@context": { "name": "http://schema.org/name" } } 
  • or a string representing the URI of an external JSON-LD file containing such a JSON object:

    { "@context": "https://json-ld.org/contexts/person.jsonld" } 

However, when used with the schema.org vocabulary, @context is always used this way:

{ "@context": "http://schema.org", } 

Even though http://schema.org is not the URI of a JSON-LD document.

What did I miss?

1 Answer 1

3

Schema.org uses content negotiation to provide the JSON-LD context file.

If you request http://schema.org while sending the request header that you accept/prefer application/ld+json, this is what happens:

  1. http://schema.org 301-redirects to https://schema.org/

    HTTP/1.1 301 Moved Permanently Content-Type: text/html Location: https://schema.org/ 
  2. https://schema.org/ 302-redirects to https://schema.org/docs/jsonldcontext.jsonld

    HTTP/1.1 302 Found Content-Type: text/html; charset=utf-8 Location: https://schema.org/docs/jsonldcontext.jsonld 
  3. https://schema.org/docs/jsonldcontext.jsonld gets delivered

    HTTP/1.1 200 OK Content-Type: application/ld+json; charset=utf-8 

You can test it yourself with curl:

curl -L -H "Accept: application/ld+json" http://schema.org 

-L makes curl follow redirects
-H includes the following header (Accept: application/ld+json) in the request

2
  • It did not even cross my mind that content negotiation could be used in this context. This makes perfect sense. Thank you! Commented Jun 11, 2019 at 23:22
  • My understanding is that as of writin jsonld instead relies on the HTTP Link header to retrieve jsonld contexts. You can verify it by running curl -IL http://schema.org. Check out w3.org/TR/json-ld11-api/#loaddocumentcallback for the current algorithm. Commented Jun 17, 2020 at 13:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.