Prefer XML Schema data types in @context to schema.org ones

In the context of a discussion started by @trwnh on improving the JSON-LD @context for #software:lemmy I want to mention the finding we came to with regards to using data types, proposing that as a best-practice. Dedicating a separate topic for findability.

Best practice: In the JSON-LD @context use XML Schema data types to define JSON-LD value properties.

The JSON-LD 1.1 Data Model specifies:

A JSON-LD value is a typed value, a string (which is interpreted as a typed value with type xsd:string ), a number (numbers with a non-zero fractional part, i.e., the result of a modulo‑1 operation, or which are too large to represent as integers (see Data Round Tripping) in [JSON-LD11-API]), are interpreted as typed values with type xsd:double , all other numbers are interpreted as typed values with type xsd:integer ), true or false (which are interpreted as typed values with type xsd:boolean ), or a language-tagged string.

Here’s the W3C XML Schema Part 2: Datatypes Second Edition specification. The most used are the Primitive datatypes are :

3.2.1 string
3.2.2 boolean
3.2.3 decimal
3.2.4 float
3.2.5 double
3.2.6 duration
3.2.7 dateTime
3.2.8 time
3.2.9 date
3.2.10 gYearMonth
3.2.11 gYear
3.2.12 gMonthDay
3.2.13 gDay
3.2.14 gMonth
3.2.15 hexBinary
3.2.16 base64Binary
3.2.17 anyURI
3.2.18 QName
3.2.19 NOTATION



A number of federated apps, like #software:peertube use(d) schema.org data types instead. One advantage is that schema.org offers a JSON-LD definition (but it is large with 1.4 MB). Disadvantages are:

  • W3C standards including all Linked Data standards (and ActivityPub too) use XML Schema Data types.
  • There are compatibility issues translating between one and the other, even for schema:Date that is more often used.

A mapping for going from schema.org to XML Schema data types hasn’t been created (the unresolved issue closed by a bot):

1 Like