w3c / json-ld-syntax

JSON-LD 1.1 Specification
https://w3c.github.io/json-ld-syntax/
Other
111 stars 22 forks source link

Playground does not match the specifications #379

Closed SvenPVoigt closed 2 years ago

SvenPVoigt commented 2 years ago

Hello all,

In the specification https://www.w3.org/TR/json-ld/#iris there are three rules for what json values can be converted to IRIs:

  1. Map entries that have a key mapping to a term in the active context expand to an IRI (only applies outside of the context definition).
  2. An IRI is generated for the string value specified using @id or @type.
  3. An IRI is generated for the string value of any key for which there are coercion rules that contain an @type key that is set to a value of @id or @vocab.

However, in the playground, when I expand the object:

{
  "@id": "_:1",
  "@context": "http://schema.org/",
  "contentUrl": "url"
}

The expanded form shows:

[
  {
    "@id": "_:1",
    "http://schema.org/contentUrl": [
      {
        "@id": "https://json-ld.org/playground/url"
      }
    ]
  }
]

The use of @id indicates that the contentUrl was interpreted as an IRI, even though none of the three conditions were met. contentUrl should have been interpreted as an @value according to the specification.

gkellogg commented 2 years ago

The http://schema.org/ context defines contentUrl using "@type": "@id", as you would expect.

SvenPVoigt commented 2 years ago

Thanks for pointing that out. It is not as I would expect, since URL is a datatype, which is used to type RDF literals not IRIs. For example, the superclass of URL is text, which is obviously a datatype.

SvenPVoigt commented 2 years ago

I would also expect about to be @type: @id since it is supposed to reference Things, which would have @id attributes. I guess my confusion is with schema.org's jsonld implementation then.

gkellogg commented 2 years ago

In JSON-LD, IRIs are identifiers (it's in the name). Literals are not identifiers, but may be values. It's true that there is an xsd:anyUri datatype, that is appropriate to use for literals that have the form of a URI.

JSON-LD takes the model from RDF, which basically has identifiers and literals, with literals only appearing in the object (value) position. If an identifier is used as the value (such as an IRI or blank node), it refers to another entity, possibly in the same file, which is used by the framing and flattening algorithms.

gkellogg commented 2 years ago

I would also expect about to be @type: @id since it is supposed to reference Things, which would have @id attributes. I guess my confusion is with schema.org's jsonld implementation then.

Schema.org is conservative in implicitly casting properly values as @id, and will accept most anything. As you can see with contentUrl, there are exceptions, but that one is fairly clearly intended to be an identifier (actually, resource locator). You might say {"about": "Bob"}, and Google may be able to make sense of that, even though "Bob" isn't necessarily an identifier.

These things are probably best discussed on Stack Overflow or Gitter, rather than as issues against the specification. Issues regarding the playground can be made on https://github.com/json-ld/json-ld.org/issues.