Search code examples
json-ldiri

Multiple terms referring to one IRI


I want to create a context file to use for multiple data sources. Is it possible to state different terms that will refer to the exact same IRI?

For example:

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

Solution

  • If I understand your question correctly, you want to define different aliases for the same property. So without the use of prefixes, this:

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

    This should be valid. In an object, the keys must be unique, but there is no such requirement for the values.


    You can test it in the JSON-LD Playground.

    This example uses the four ways how the property could be specified:

    {
      "@context": {
        "bi": "http://schema.org/",
        "twitter_name": "bi:name",
        "facebook_name": "bi:name"
      },
      "bi:name": "Alice (prefix)",
      "twitter_name": "Alice (alias for Twitter)",
      "facebook_name": "Alice (alias for Facebook)",
      "http://schema.org/name": "Alice (full URI)"
    }
    

    The compacted result contains an array value with the four names:

    {
      "http://schema.org/name": [
        "Alice (prefix)",
        "Alice (alias for Facebook)",
        "Alice (full URI)",
        "Alice (alias for Twitter)"
      ]
    }
    

    So all the keys are correctly interpreted to be Schema.org’s name property.