Despite its original XML syntax, the RDF data model is not aligned with existing Web formats: HTML (XML), JSON.
A revision of the RDF/XML syntax was designed to appeal to Web developers.
It didn't.
One possible reason for this lack of adoption is the lack of idiomatic representations of RDF data in object-oriented programming languages.
The gap between objects and triples is "too wide"...
...despite numerous object-triple mapping libraries (Ledvinka, 2018)
In addition, Web developers typically build "full-stack" applications, including a front-end, a back-end and communication between the two.
They don't particularly need to expose data in an interoperable way (i.e. with URIs everywhere).
But full-stack Web applications are not the only kind of Web app.
On the Linked Open Data (LOD) cloud, the effort is split:
RDF can help redistribute the effort between client and server applications on the Web.
Two technologies (among others) tend towards that objective:
JSON: JavaScript Object Notation
JSON values can be objects, arrays or simple values.
Type | Example |
---|---|
Null | null |
Boolean | true , false |
Number | 2.4 |
String | "abc" |
Object | { "a": 2.4, "b": "abc", ... } |
Array | [ 2.4, "abc", ... ] |
"That’s it. That is all of JSON." — Douglas Crockford (Crockford, 2008)
Objects (in Java, Python, C#, etc.) can easily be (de)serialized in JSON.
RDF-based applications often require a transformation from/to objects.
↪ Can there be a standard JSON serialization of RDF?
@Namespaces({
"frbr", "http://vocab.org/frbr/core#",
"dc", "http://purl.org/dc/terms/",
"foaf", "http://xmlns.com/foaf/0.1/"
})
@RdfsClass("frbr:Expression")
@Entity
public class Book implements SupportsRdfId {
@RdfProperty("dc:title")
private String mTitle;
@RdfProperty("dc:publisher")
private String mPublisher;
@RdfProperty("dc:issued")
private Date mIssued;
@RdfProperty("foaf:primarySubjectOf")
private URI mPrimarySubjectOf;
@OneToMany(fetch = FetchType.LAZY,
cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@RdfProperty("frbr:embodiment")
private Collection<Manifestation> mEmbodiments = new HashSet<Manifestation>();
// ...
}
{
"@context": {
"frbr": "http://vocab.org/frbr/core#",
"dc": "http://purl.org/dc/terms/",
"foaf": "http://xmlns.com/foaf/0.1/",
"mTitle": "dc:title",
"mPublisher": "dc:publisher",
"mIssued": {
"@id": "dc:issued",
"@type": "http://www.w3.org/2001/XMLSchema#date"
}, "mPrimarySubjectOf": {
"@id": "foaf:primarySubjectOf",
"@type": "@id"
}, "mEmbodiments": {
"@id": "frbr:embodiment",
"@container": "@set"
}
},
"@id": "http://www.wikidata.org/entity/Q13912",
"@type": "frbr:Expression",
"mTitle": "Where the Wild Things Are",
"mPublisher": "Harper & Raw",
"mIssued": "1963-11-13",
"mPrimarySubjectOf": "https://en.wikipedia.org/wiki/Where_the_Wild_Things_Are",
"mEmbodiments": [
...
]
}
JSON-LD: JSON for Linked Data
A JSON-LD document has (at least) two forms:
Try the JSON-LD Playground to process all forms of JSON-LD.
[
{
"@id": "http://www.wikidata.org/entity/Q13912",
"http://purl.org/dc/terms/title": [
{
"@value": "Where the Wild Things Are"
}
],
"http://purl.org/dc/terms/publisher": [
{
"@value": "Harper & Raw"
}
],
"http://purl.org/dc/terms/issued": [
{
"@value": "1963-11-13",
"@type": "http://www.w3.org/2001/XMLSchema#date"
}
],
"http://xmlns.com/foaf/0.1/primarySubjectOf": [
{
"@id": "https://en.wikipedia.org/wiki/Where_the_Wild_Things_Are"
}
],
"http://vocab.org/frbr/core#embodiment": [ ... ],
}
]
A JSON-LD object can be:
@id
)@value
)
In its compacted form, a JSON-LD document has a context
(with key @context
).
A JSON-LD context maps arbitrary JSON strings to IRIs.
A JSON-LD context includes several kinds of definitions.
See section 6 "Advanced concepts" of the JSON-LD W3C specification.
Compact IRIs: instead of full IRIs, JSON object keys can map to IRIs compacted with a declared prefix.
{
"@context": {
"dc": "http://purl.org/dc/terms/",
"mTitle": "dc:title",
"mPublisher": "dc:publisher"
}
}
Typed Values: a default datatype range can be given to JSON object keys.
{
"@context": {
"dc": "http://purl.org/dc/terms/",
"mIssued": {
"@id": "dc:issued",
"@type": "http://www.w3.org/2001/XMLSchema#date"
}
}
}
Type Coercion: a JSON string can map to a string literal or to an IRI.
{
"@context": {
"foaf": "http://xmlns.com/foaf/0.1/",
"mPrimarySubjectOf": {
"@id": "foaf:primarySubjectOf",
"@type": "@id"
}
}
}
Sets and Lists: JSON arrays can map to unordered sets of triples or to RDF lists.
{
"@context": {
"frbr": "http://vocab.org/frbr/core#",
"mEmbodiments": {
"@id": "frbr:embodiment",
"@container": "@set"
}
}
Schema.org is a collection of RDF classes and properties to describe entities typically described in Web pages.
Schema.org also provides a default JSON-LD context for Web developers to use.
{
"@context":"http://schema.org",
"@type":"Movie",
"contentRating":"PG",
"dateCreated":"2009-10-16",
"genre":["Kids & Family","Fantasy","Adventure"],
"name":"Where the Wild Things Are",
"url":"https://www.rottentomatoes.com/m/where_the_wild_things_are",
"actor":[
{
"@type":"Person",
"name":"Catherine Keener",
"sameAs":"https://www.rottentomatoes.com/celebrity/catherine_keener"
},
{
"@type":"Person",
"name":"Max Records",
"sameAs":"https://www.rottentomatoes.com/celebrity/max-records"
},
...
]
}
JSON-LD data can be embedded in any Web page...
...including this one. To embed data:
<script>
element"type"="application/ld+json"
Schema.org annotations are everywhere on the Web.
E.g. on Rotten Tomatoes.
But not on Google or Amazon websites.
Web developers have tools for testing their schema.org annotations:
Other Web annotations framework have got lesser attention but pursue the same goal:
JSON-LD, Schema.org and, to a lesser extent, RDFa and Microdata are present in:
HTTP Archive's dataset is based on user browsing habits whereas Web Data Commons is based on pure hypermedia navigation, hence some discrepancy between the two.