In 2011 mnot wrote about json linking. Now it's like 4 years later
and time to take a look at the link formats in json, which are used by lots of people.
In HTML5 we have a
<link> tag defined like this:
<link rel="author license" href="/about">
The attributes of this link are defined like this (taken from the W3C-page):
- href — Address of the hyperlink
- crossorigin — How the element handles crossorigin requests
- rel — Relationship between the document containing the hyperlink and the destination resource
- media — Applicable media
- hreflang — Language of the linked resource
- type — Hint for the type of the referenced resource
- sizes — Sizes of the icons (for rel="icon")
- Also, the title attribute has special semantics on this element: Title of the link; alternative style sheet set name.
The advantage of the
<link> tag in XML is, that you could put it anywhere in your document (like the
<a> tag in HTML).
If you want to achieve web linking (rfc5988) in JSON, there are multiple approaches.
This post shows some of the widely used JSON media types and how they deal with links. I will have a short look at HAL, Collection+JSON,
Hydra/JSON-LD, Mason, Siren and UBER. Example files for all of them are in this json links gist.