Skip to content

declare datatype in $linkedData #576

@VladimirAlexiev

Description

@VladimirAlexiev

In a JSONLD context one can and should declare the datatypes of props, so that a JSON payload string is mapped to the appropriate datatype.

  • (This is unlike the expected range of an object property, which cannot be declared, because the type of all such props is @is)

This is especially important for literals that don't have native JSON type (xsd:date, xsd:dateTime).
It's also important for numbers, which are subject to rounding/mangling in JSON. Eg this JSONLD payload:

{"@context":{
   "xsd":"http://www.w3.org/2001/XMLSchema#",
   "foo": {"@type":"xsd:boolean","@id":"https://example.org/foo"},
   "foo1":{"@type":"xsd:boolean","@id":"https://example.org/foo1"},
   "bar": {"@type":"xsd:decimal","@id":"https://example.org/bar"},
   "bar1":{"@type":"xsd:decimal","@id":"https://example.org/bar1"},
   "baz": {"@type":"xsd:integer","@id":"https://example.org/baz"}
  },
  "foo":"true","foo1":true,"bar":"12.345678901234567890","bar1":12.345678901234567890,"baz":123456789012345678901234567890}

is converted to this ntriples at https://json-ld.org/playground/.
Notice the rounding of bar1, and the syntactically incorrect value of baz:

_:b0 <https://example.org/bar1> "1.234567890123457E1"^^<http://www.w3.org/2001/XMLSchema#decimal> .
_:b0 <https://example.org/bar> "12.345678901234567890"^^<http://www.w3.org/2001/XMLSchema#decimal> .
_:b0 <https://example.org/baz> "1.234567890123457E29"^^<http://www.w3.org/2001/XMLSchema#integer> .
_:b0 <https://example.org/foo1> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
_:b0 <https://example.org/foo> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .

It's less important for booleans because the values are not subject to rounding.

Examples:

  1. credentials/USMCACertificationOfOrigin.yml:
  importerUnknown:
    title: Importer Unknown
    description: >-
      If the identity of the importer is unknown, or there are various
      importers, please check the appropriate box.
    type: boolean
    $linkedData:
      term: importerUnknown
      '@id': https://w3id.org/traceability#importerUnknown

could add

      '@type': 'xsd:boolean'
  1. common/IATAAirWaybill.yml:
  executedOn:
    title: Executed on (Date)
    description: >-
      The date of execution of the air waybill shall be inserted in the sequence
      of day, month and year. The month shall be expressed alphabetically,
      either abbreviated or in full. Box 32A.
    type: string
    $linkedData:
      term: executedOn
      '@id': https://w3id.org/traceability#executionTime
      '@type': http://www.w3.org/2001/XMLSchema#dateTime

already has @type, but maybe the JSON type should be changed from string to something better?

  1. common/Transport.yml:
  plannedDepartureDate:
    title: Planned Departure Date
    description: The planned date of departure.
    type: string
    $linkedData:
      term: plannedDepartureDate
      '@id': https://schema.org/Date

Must change to this ( I assume JSON Schema has type dateTime)

    type: dateTime 
    $linkedData:
       term: plannedDepartureDate
       '@id': traceability:plannedDepartureDate
       '@type': xsd:dateTime

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededpost-1.0This is for issues that are important but should not block 1.0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions