Skip to content

Instantly share code, notes, and snippets.

@donaldpipowitch
Created September 14, 2017 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donaldpipowitch/a3c55d6d5e5ee09ac99d4fcada50c70f to your computer and use it in GitHub Desktop.
Save donaldpipowitch/a3c55d6d5e5ee09ac99d4fcada50c70f to your computer and use it in GitHub Desktop.
Relations in JSON-LD

I don't know, if it is correct to use IANA relations in this way and to add custom relations.

But these examples are parsed in the same way.

inlined relations

{
  "http://www.iana.org/assignments/relation/self": {
    "@id": "https://api.example.com/users/1"
  },
  "https://rel.example.com/mother": {
    "@id": "https://api.example.com/users/2"
  },
  "https://rel.example.com/father": {
    "@id": "https://api.example.com/users/3"
  },
  "id": "1",
  "name": "Jon Doe"
}

relations in @context

{
  "@context": {
    "self": {
      "@id": "http://www.iana.org/assignments/relation/self",
      "@type": "@id"
    },
    "mother": {
      "@id": "https://rel.example.com/mother",
      "@type": "@id"
    },
    "father": {
      "@id": "https://rel.example.com/father",
      "@type": "@id"
    }
  },
  "self": "https://api.example.com/users/1",
  "mother": "https://api.example.com/users/2",
  "father": "https://api.example.com/users/3",
  "id": "1",
  "name": "Jon Doe"
}

relations with compact URIs

Similar to CURIEs in HAL.

{
  "@context": {
    "iana": "http://www.iana.org/assignments/relation/",
    "ex": "https://rel.example.com/",
    "self": {
      "@id": "iana:self",
      "@type": "@id"
    },
    "mother": {
      "@id": "ex:mother",
      "@type": "@id"
    },
    "father": {
      "@id": "ex:father",
      "@type": "@id"
    }
  },
  "self": "https://api.example.com/users/1",
  "mother": "https://api.example.com/users/2",
  "father": "https://api.example.com/users/3",
  "id": "1",
  "name": "Jon Doe"
}

compacted view

Just to show they are parsed in the same way. This is the compacted view (from JSON-LD playground) for all of them:

{
  "http://www.iana.org/assignments/relation/self": {
    "@id": "https://api.example.com/users/1"
  },
  "https://rel.example.com/father": {
    "@id": "https://api.example.com/users/3"
  },
  "https://rel.example.com/mother": {
    "@id": "https://api.example.com/users/2"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment