JSON-LD: JSON for Linked Data

gkellogg1 74,225 views 50 slides May 30, 2012
Slide 1
Slide 1 of 50
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50

About This Presentation

JSON-LD is a set of W3C standards track specifications for representing Linked Data in JSON. It is fully compatible with the RDF data model, but allows developers to work with data entirely within JSON.

More information on JSON-LD can be found at http://json-ld.org/


Slide Content

JSON-LD
JSON for Linked Data
Gregg Kellogg
[email protected]
@gkellogg

JSON-LD
JSON for Linked Data
Gregg Kellogg
[email protected]
@gkellogg
Linking

JSON
JSON has taken over service APIs

Tower of Babel

Tower of Babel
{
"type": "User",
"followers": 35,
"html_url": "https://github.com/gkellogg",
"hireable": true,
"created_at": "2009-01-13T16:58:46Z",
"public_repos": 44,
"blog": "http://greggkellogg.net",
"bio": "Gregg is a Standards Architect ...",
"gravatar_id":
"42f948ad!3afaa52249d963117af7c8",
"following": 35,
"company": "Self",
"public_gists": 4,
"location": "San Rafael, CA",
"name": "Gregg Kellogg",
"email": "[email protected]",
"url": "https://api.github.com/users/gkellogg",
"avatar_url": "...",
"id": 46296,
"login": "gkellogg"
GitHub

Tower of Babel
{
"type": "User",
"followers": 35,
"html_url": "https://github.com/gkellogg",
"hireable": true,
"created_at": "2009-01-13T16:58:46Z",
"public_repos": 44,
"blog": "http://greggkellogg.net",
"bio": "Gregg is a Standards Architect ...",
"gravatar_id":
"42f948ad!3afaa52249d963117af7c8",
"following": 35,
"company": "Self",
"public_gists": 4,
"location": "San Rafael, CA",
"name": "Gregg Kellogg",
"email": "[email protected]",
"url": "https://api.github.com/users/gkellogg",
"avatar_url": "...",
"id": 46296,
"login": "gkellogg"
GitHub
{
"max_id": 195520745634406400,
"page": 1,
"query": "%40gkellogg",
"results": [{
"created_at": "Thu, 26 Apr 2012 14:32:33
+0000",
"from_user": "kendall",
"from_user_name": "Kendall Clark",
"id": 195520745634406400,
"in_reply_to_status_id":
195518881811529729,
"iso_language_code": "en",
"metadata": {"result_type": "recent"},
"text": "@Gkellogg Multiple resources in a
single JSON-LD struct/doc/message.",
"to_user": "Gkellogg",
"to_user_id": 6125262,
"to_user_name": "Gregg Kellogg"
}],
"results_per_page": 1,
"since_id": 0,
"since_id_str": "0"
}
Twitter

Tower of Babel
{
"type": "User",
"followers": 35,
"html_url": "https://github.com/gkellogg",
"hireable": true,
"created_at": "2009-01-13T16:58:46Z",
"public_repos": 44,
"blog": "http://greggkellogg.net",
"bio": "Gregg is a Standards Architect ...",
"gravatar_id":
"42f948ad!3afaa52249d963117af7c8",
"following": 35,
"company": "Self",
"public_gists": 4,
"location": "San Rafael, CA",
"name": "Gregg Kellogg",
"email": "[email protected]",
"url": "https://api.github.com/users/gkellogg",
"avatar_url": "...",
"id": 46296,
"login": "gkellogg"
GitHub
{
"max_id": 195520745634406400,
"page": 1,
"query": "%40gkellogg",
"results": [{
"created_at": "Thu, 26 Apr 2012 14:32:33
+0000",
"from_user": "kendall",
"from_user_name": "Kendall Clark",
"id": 195520745634406400,
"in_reply_to_status_id":
195518881811529729,
"iso_language_code": "en",
"metadata": {"result_type": "recent"},
"text": "@Gkellogg Multiple resources in a
single JSON-LD struct/doc/message.",
"to_user": "Gkellogg",
"to_user_id": 6125262,
"to_user_name": "Gregg Kellogg"
}],
"results_per_page": 1,
"since_id": 0,
"since_id_str": "0"
}
Twitter
{
"id": "1236600216",
"name": "Gregg Kellogg",
"first_name": "Gregg",
"last_name": "Kellogg",
"link": "https://www.facebook.com/
gkellogg",
"username": "gkellogg",
"gender": "male",
"locale": "en_US"
}
Facebook

Introducing JSON-LD
JSON-based syntax to express linked data
@context
@id
@type
@value
@language
@graph
@list
@set

Self-describing Messages

Give objects types
(@type)
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"colleagues": {"@id": "schema:colleagues", "@type": "@id"},
"name": "schema:name",
"image": {"@id": "schema:image", "@type": "@id"},
"url": {"@id": "schema:url", "@type": "@id"}
}
}
{
"@context": "http://example.com/context.jsonld",
"@type": "Person",
"image": "http://localhost:9393/examples/schema.org/janedoe.jpg",
"colleagues": [
"http://www.xyz.edu/students/alicejones.html",
"http://www.xyz.edu/students/bobsmith.html"
],
"name": "Jane Doe",
"url": "http://www.janedoe.com"
}

Self-describing Messages

Give objects types
(@type)

Associate properties
with IRIs
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"colleagues": {"@id": "schema:colleagues", "@type": "@id"},
"name": "schema:name",
"image": {"@id": "schema:image", "@type": "@id"},
"url": {"@id": "schema:url", "@type": "@id"}
}
}
{
"@context": "http://example.com/context.jsonld",
"@type": "Person",
"image": "http://localhost:9393/examples/schema.org/janedoe.jpg",
"colleagues": [
"http://www.xyz.edu/students/alicejones.html",
"http://www.xyz.edu/students/bobsmith.html"
],
"name": "Jane Doe",
"url": "http://www.janedoe.com"
}

Self-describing Messages

Give objects types
(@type)

Associate properties
with IRIs

Use terms defined in a
referenced context
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"colleagues": {"@id": "schema:colleagues", "@type": "@id"},
"name": "schema:name",
"image": {"@id": "schema:image", "@type": "@id"},
"url": {"@id": "schema:url", "@type": "@id"}
}
}
{
"@context": "http://example.com/context.jsonld",
"@type": "Person",
"image": "http://localhost:9393/examples/schema.org/janedoe.jpg",
"colleagues": [
"http://www.xyz.edu/students/alicejones.html",
"http://www.xyz.edu/students/bobsmith.html"
],
"name": "Jane Doe",
"url": "http://www.janedoe.com"
}

Self-describing Messages

Give objects types
(@type)

Associate properties
with IRIs

Use terms defined in a
referenced context

Specify property types
in context
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"colleagues": {"@id": "schema:colleagues", "@type": "@id"},
"name": "schema:name",
"image": {"@id": "schema:image", "@type": "@id"},
"url": {"@id": "schema:url", "@type": "@id"}
}
}
{
"@context": "http://example.com/context.jsonld",
"@type": "Person",
"image": "http://localhost:9393/examples/schema.org/janedoe.jpg",
"knows": [
"http://www.xyz.edu/students/alicejones.html",
"http://www.xyz.edu/students/bobsmith.html"
],
"name": "Jane Doe",
"url": "http://www.janedoe.com"
}

Language Principles

{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": "http://www.markus-lanthaler.com/"
}

Make full use of JSON syntactic
representations

Object defines a subject
definition

{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": "http://www.markus-lanthaler.com/"
}

Make full use of JSON syntactic
representations

Object defines a subject
definition
{ "@id": "http://greggkellogg.net/foaf#me" }

Also used for subject
reference and value
representations

{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": "http://www.markus-lanthaler.com/"
}

Make full use of JSON syntactic
representations

Object defines a subject
definition
{ "@id": "http://greggkellogg.net/foaf#me" }

Also used for subject
reference and value
representations

Arrays describe sets of unordered
values

Single values can skip array
{
"@type": "Recipe",
"name": "Mom's World Famous Banana Bread",
"ingredients": [
"3 or 4 ripe bananas, smashed",
"1 egg",
"3/4 cup of sugar"
],
"nutrition": [{
"@type": ["NutritionInformation"],
"calories": ["240 calories"],
"fatContent": ["9 grams fat"]
}]
}

{
"@id": "http://greggkellogg.net/foaf#me",
"@type": "http://schema.org/Person",
"http://schema.org/name": "Gregg Kellogg",
"http://schema.org/knows": {
"@id": "http://www.markus-lanthaler.com/"
}
}

Define terms to use short
property names

Convenient for JavaScript “.”
notation
{
"@context": {
"Person": "http://schema.org/Person",
"name": "http://schema.org/name",
"knows”: "http://schema.org/knows"
},
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": {"@id": "http://www.markus-lanthaler.com/"}
}


Define terms to use short
property names

Convenient for JavaScript “.”
notation

Add @type coercions to
use simple string value.
{
"@id": "http://greggkellogg.net/foaf#me",
"@type": "http://schema.org/Person",
"http://schema.org/name": "Gregg Kellogg",
"http://schema.org/knows": {
"@id": "http://www.markus-lanthaler.com/"
}
}
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"name": "schema:name",
"knows”: {
"@id": "schema:knows",
"@type": "@id"
},
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": "http://www.markus-lanthaler.com/"
}


Define terms to use short
property names

Convenient for JavaScript “.”
notation

Add @type coercions to
use simple string value.
{
"@id": "http://greggkellogg.net/foaf#me",
"@type": "http://schema.org/Person",
"http://schema.org/name": "Gregg Kellogg",
"http://schema.org/knows": {
"@id": "http://www.markus-lanthaler.com/"
}
}
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"name": "schema:name",
"knows”: {
"@id": "schema:knows",
"@type": "@id"
}
}

Use external @context.
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": "http://www.markus-lanthaler.com/"
}


Define referenced subject
definition with chaining
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": {
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
}


Define referenced subject
definition with chaining
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": {
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
}

Add @language to values.{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"honorificSuffix": {"@value": "M.S.", "@language": "en"},
"knows": {
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"honorificSuffix": {"@value": "Dipl.Ing.", "@language": "de"},
"knows" "http://greggkellogg.net/foaf#me"
}
}


Add @type to values.

Link to externally defined
resources.
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"birthDate": {"@value": "1957-02-27", "@type": "xsd:date"},
"honorificSuffix": {"@value": "M.S.", "@language": "en"},
"knows": "http://www.markus-lanthaler.com/"
}


Add property @type and
@language definitions to
context
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"name": "schema:name",
"birthDate”: {
"@id": "schema: birthDate","@type": "xsd:date"
},
"honorificSuffix”: {
"@id": "schema:honorificSuffix","@language": "en"
},
"knows”: {"@id": "schema:knows","@type": "@id"}
},
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"birthDate": "1957-02-27",
"honorificSuffix": "M.S.",
"knows": "http://www.markus-lanthaler.com/"
}

•More features defined in the syntax
specification*:
•@set, @list, Compact IRIs, Unlabeled
Nodes
•Embedded @context definitions
•Named Graphs
* http://json-ld.org/spec/latest/json-ld-syntax

Examples “In the Wild”

DBpedia
{
"@graph": [
{
"@id": "http://dbpedia.org/resource/DBpedia",
"http://dbpedia.org/property/genre" : [ "http://dbpedia.org/resource/Linked_Data" ]
} ,
{
"@id": "http://dbpedia.org/resource/Linked_Data",
"@type" : [ "http://dbpedia.org/class/yago/Buzzwords" ] ,
"http://www.w3.org/2002/07/owl#sameAs" : ["http://rdf.freebase.com/ns/m/02r2kb1"] ,
"http://www.w3.org/2000/01/rdf-schema#comment": [
{ "@value" : "Linked Open Data (LOD) bezeichnet ..." , "@language" : "de" } ,
{ "@value" : "In computing, linked Data describes ..." , "@language" : "en" } ],
"http://purl.org/dc/terms/subject" : [
"http://dbpedia.org/resource/Category:World_Wide_Web" ,
"http://dbpedia.org/resource/Category:Buzzwords" ,
"http://dbpedia.org/resource/Category:Semantic_Web"
] ,
...
}]
}
http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=DESCRIBE+<http://dbpedia.org/resource/
Linked_Data>&output=application%2Fld%2Bjson

Schema.org
http://linter.structured-data.org/examples/
schema.org/sdo_eg_rdfa_12.html
Using RDFa to JSON-LD bookmarklet*
* bookmarklet courtesy of Niklas Lindström

Schema.org
http://linter.structured-data.org/examples/
schema.org/sdo_eg_rdfa_12.html
{
"@context": {...},
"@graph": [{
"@id": "http://linter.structured-data.org/examples/schema.org/Recipe.rdfa",
"rdfa:usesVocabulary": "http://schema.org/"
}, {
"@type": ["Recipe"],
"name": ["Mom's World Famous Banana Bread"],
"author": ["John Smith"],
"publishDate": ["2009-05-08"],
"image": [{"@id": ".../bananabread.jpg"}],
"description": ["This classic banana bread recipe ..."],
"prepTime": ["PT15M"],
"cookTime": ["PT1H"],
"recipeYield": ["1 loaf"],
"nutrition": [{
"@type": ["NutritionInformation"],
"calories": ["240 calories"],
"fatContent": ["9 grams fat"]
}],
"ingredients": [
"3 or 4 ripe bananas, smashed",
"1 egg",
"3/4 cup of sugar"
],
"recipeInstructions": ["Preheat the oven to 350 degrees..."],
"interactionCount": ["UserComments:140"]
}]
}
Using RDFa to JSON-LD bookmarklet*
* bookmarklet courtesy of Niklas Lindström

Drupal

Drupal
{
"@context": "http://drupal.example.org/context.jsonld",
"@id": "http://dev.fga-directory.gotpantheon.com/
occupation/al/kosovo/occupy-prishtina",
"@type": ["ows:Occupation", "schema:Organization"],
"foaf:name": "Occupy Prishtina",
"schema:name": "Occupy Prishtina",
"dc:date": "2012-02-12T21:18:08-05:00",
"dc:created": "2012-02-12T21:18:08-05:00",
"dc:modified": "2012-02-12T21:57:52-05:00",
"sioc:num_replies": 0,
"schema:foundingDate": "2011-10-15T00:00:00-04:00",
"ows:twitter_account": "@OccupyPrishtina",
"foaf:mbox": "",
"schema:telephone": "",
"foaf:phone": ""
}
http://dev.fga-directory.gotpantheon.com/node/20080.jsonld

PaySwarm
{
"@context": "http://purl.org/payswarm/v1",
"@graph": {
"@type": "Transaction",
"transfer": {
"@type": "Transfer",
"amount": "7.50",
"currency": "USD",
"source": "https://bluebank.com/people/manu/accounts/food",
"destination": "https://redbank.com/people/gregg/accounts/hosting",
"comment": "Chipping in for the Pizza Party tomorrow."
},
},
"signature": {
"@type": "JsonLdSignature",
"created": "2011-09-23T20:21:34Z",
"signer": "http://bluebank.com/people/manu/keys/5",
"signatureValue": "ExMgoDIyOGQzNGVkM...mOWM32Nj4NTIyZTkZDYMI="
}
}Named
Graph Signature of
Named
Graph

Working with data
{
"@context": "http://drupal.example.org/context.jsonld",
"@id": "http://dev.fga-directory.gotpantheon.com/
occupation/al/kosovo/occupy-prishtina",
"@type": ["ows:Occupation", "schema:Organization"],
"foaf:name": "Occupy Prishtina",
"schema:name": "Occupy Prishtina",
"dc:date": "2012-02-12T21:18:08-05:00",
"dc:created": "2012-02-12T21:18:08-05:00",
"dc:modified": "2012-02-12T21:57:52-05:00",
"sioc:num_replies": 0,
"schema:foundingDate": "2011-10-15T00:00:00-04:00",
"ows:twitter_account": "@OccupyPrishtina",
"foaf:mbox": "",
"schema:telephone": "",
"foaf:phone": ""
}

Expand documents to remove effect of @context.

Working with data
{
"@context": "http://drupal.example.org/context.jsonld",
"@id": "http://dev.fga-directory.gotpantheon.com/
occupation/al/kosovo/occupy-prishtina",
"@type": ["ows:Occupation", "schema:Organization"],
"foaf:name": "Occupy Prishtina",
"schema:name": "Occupy Prishtina",
"dc:date": "2012-02-12T21:18:08-05:00",
"dc:created": "2012-02-12T21:18:08-05:00",
"dc:modified": "2012-02-12T21:57:52-05:00",
"sioc:num_replies": 0,
"schema:foundingDate": "2011-10-15T00:00:00-04:00",
"ows:twitter_account": "@OccupyPrishtina",
"foaf:mbox": "",
"schema:telephone": "",
"foaf:phone": ""
}

Expand documents to remove effect of @context.
[{
"@id": "http://dev.fga-directory.gotpantheon.com/occupation/al/kosovo/occupy-prishtina",
"@type": ["http://vocab.occupy.net/ows#Occupation", "http://schema.org/Organization"],
"http://purl.org/dc/terms/created": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:18:08-05:00"
}],
"http://purl.org/dc/terms/date": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:18:08-05:00"
}],
"http://purl.org/dc/terms/modified": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:57:52-05:00"
}],
"http://rdfs.org/sioc/ns#num_replies": [{
"@type": "http://www.w3.org/2001/XMLSchema#integer",
"@value": "0"
}],
"http://schema.org/foundingDate": [{
"@type": "http://www.w3.org/2001/XMLSchema#date",
"@value": "2011-10-15T00:00:00-04:00"
}],
"http://schema.org/name": ["Occupy Prishtina"],
"http://schema.org/telephone": [""],
"http://vocab.occupy.net/ows#twitter_account": ["@OccupyPrishtina"],
"http://xmlns.com/foaf/0.1/mbox": [""],
"http://xmlns.com/foaf/0.1/name": ["Occupy Prishtina"],
"http://xmlns.com/foaf/0.1/phone": [""]
}]

[{
"@id": "http://dev.fga-directory.gotpantheon.com/occupation/al/kosovo/occupy-prishtina",
"@type": ["http://vocab.occupy.net/ows#Occupation", "http://schema.org/Organization"],
"http://purl.org/dc/terms/created": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:18:08-05:00"
}],
"http://purl.org/dc/terms/date": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:18:08-05:00"
}],
"http://purl.org/dc/terms/modified": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:57:52-05:00"
}],
"http://rdfs.org/sioc/ns#num_replies": [{
"@type": "http://www.w3.org/2001/XMLSchema#integer",
"@value": "0"
}],
"http://schema.org/foundingDate": [{
"@type": "http://www.w3.org/2001/XMLSchema#date",
"@value": "2011-10-15T00:00:00-04:00"
}],
"http://schema.org/name": ["Occupy Prishtina"],
"http://schema.org/telephone": [""],
"http://vocab.occupy.net/ows#twitter_account": ["@OccupyPrishtina"],
"http://xmlns.com/foaf/0.1/mbox": [""],
"http://xmlns.com/foaf/0.1/name": ["Occupy Prishtina"],
"http://xmlns.com/foaf/0.1/phone": [""]
}]
Working with data

Compact documents to apply a @context.

[{
"@id": "http://dev.fga-directory.gotpantheon.com/occupation/al/kosovo/occupy-prishtina",
"@type": ["http://vocab.occupy.net/ows#Occupation", "http://schema.org/Organization"],
"http://purl.org/dc/terms/created": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:18:08-05:00"
}],
"http://purl.org/dc/terms/date": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:18:08-05:00"
}],
"http://purl.org/dc/terms/modified": [{
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2012-02-12T21:57:52-05:00"
}],
"http://rdfs.org/sioc/ns#num_replies": [{
"@type": "http://www.w3.org/2001/XMLSchema#integer",
"@value": "0"
}],
"http://schema.org/foundingDate": [{
"@type": "http://www.w3.org/2001/XMLSchema#date",
"@value": "2011-10-15T00:00:00-04:00"
}],
"http://schema.org/name": ["Occupy Prishtina"],
"http://schema.org/telephone": [""],
"http://vocab.occupy.net/ows#twitter_account": ["@OccupyPrishtina"],
"http://xmlns.com/foaf/0.1/mbox": [""],
"http://xmlns.com/foaf/0.1/name": ["Occupy Prishtina"],
"http://xmlns.com/foaf/0.1/phone": [""]
}]
Working with data

Compact documents to apply a @context.
{
"@context": "http://drupal.example.org/context.jsonld",
"@id": "http://dev.fga-directory.gotpantheon.com/
occupation/al/kosovo/occupy-prishtina",
"@type": ["ows:Occupation", "schema:Organization"],
"foaf:name": "Occupy Prishtina",
"schema:name": "Occupy Prishtina",
"dc:date": "2012-02-12T21:18:08-05:00",
"dc:created": "2012-02-12T21:18:08-05:00",
"dc:modified": "2012-02-12T21:57:52-05:00",
"sioc:num_replies": 0,
"schema:foundingDate": "2011-10-15T00:00:00-04:00",
"ows:twitter_account": "@OccupyPrishtina",
"foaf:mbox": "",
"schema:telephone": "",
"foaf:phone": ""
}

Working with data
{
"@context": {
"dc": "http://purl.org/dc/elements/1.1/",
"ex": "http://example.org/vocab#",
"contains": {"@type": "@id"}
},
"@graph": [{
"@id": "http://example.org/test/#library",
"@type": "ex:Library",
"ex:contains": "http://example.org/test#book"
}, {
"@id": "http://example.org/test#book",
"@type": "ex:Book",
"dc:contributor": "Writer",
"dc:title": "My Book",
"ex:contains": "http://example.org/test#chapter"
}, {
"@id": "http://example.org/test#chapter",
"@type": "ex:Chapter",
"dc:description": "Fun",
"dc:title": "Chapter One"
}]
}

Frame documents to impose structure
input

Working with data
{
"@context": {
"dc": "http://purl.org/dc/elements/1.1/",
"ex": "http://example.org/vocab#",
"contains": {"@type": "@id"}
},
"@graph": [{
"@id": "http://example.org/test/#library",
"@type": "ex:Library",
"ex:contains": "http://example.org/test#book"
}, {
"@id": "http://example.org/test#book",
"@type": "ex:Book",
"dc:contributor": "Writer",
"dc:title": "My Book",
"ex:contains": "http://example.org/test#chapter"
}, {
"@id": "http://example.org/test#chapter",
"@type": "ex:Chapter",
"dc:description": "Fun",
"dc:title": "Chapter One"
}]
}

Frame documents to impose structure
input
{
"@context": {
"dc": "http://purl.org/dc/elements/1.1/",
"ex": "http://example.org/vocab#",
"contains": {“@id”: “ex:contains”, "@type": "@id",
“title”: “dc:title”
},
"@type": "ex:Library",
"contains": {
"@type": "ex:Book",
"contains": {
"@type": "ex:Chapter"
}
}
}
+
frame

Working with data
{
"@context": {
"dc": "http://purl.org/dc/elements/1.1/",
"ex": "http://example.org/vocab#",
"contains": {"@type": "@id"}
},
"@graph": [{
"@id": "http://example.org/test/#library",
"@type": "ex:Library",
"ex:contains": "http://example.org/test#book"
}, {
"@id": "http://example.org/test#book",
"@type": "ex:Book",
"dc:contributor": "Writer",
"dc:title": "My Book",
"ex:contains": "http://example.org/test#chapter"
}, {
"@id": "http://example.org/test#chapter",
"@type": "ex:Chapter",
"dc:description": "Fun",
"dc:title": "Chapter One"
}]
}

Frame documents to impose structure
input
{
"@context": {
"dc": "http://purl.org/dc/elements/1.1/",
"ex": "http://example.org/vocab#",
"contains": {“@id”: “ex:contains”, "@type": "@id",
“title”: “dc:title”
},
"@type": "ex:Library",
"contains": {
"@type": "ex:Book",
"contains": {
"@type": "ex:Chapter"
}
}
}
+
frame
{
"@context": {
"dc": "http://purl.org/dc/elements/1.1/",
"ex": "http://example.org/vocab#",,
"contains": {“@id”: “ex:contains”, "@type": "@id"
“title”: “dc:title”
},
"@graph": [{
"@id": "http://example.org/test/#library",
"@type": "ex:Library",
"contains": {
"@id": "http://example.org/test#book",
"@type": "ex:Book",
"dc:contributor": "Writer",
"title": "My Book",
"contains": {
"@id": "http://example.org/test#chapter",
"@type": "ex:Chapter",
"dc:description": "Fun",
"title": "Chapter One"
}
}
}]
}
output
JavaScript object path: data[‘@graph][0].contains.contains.title

Retrofit existing APIs
GET /foaf.json HTTP/1.1
Host: greggkellogg.net
Accept: application/json,*/*;q=0.1
====================================
HTTP/1.0 200 OK
...
Content-Type: application/json
Link: <http://json-ld.org/contexts/person>; rel="describedby"; type="application/ld+json"
{
"name": "Gregg Kellogg",
"homepage": "http://greggkellogg.net/",
"depiction": "http://twitter.com/account/profile_image/gkellogg"
}

Macros

Transform information

Add @id to data

Other programatic
transformations
{
"type": "User",
"followers": 35,
"name": "Gregg Kellogg",
"email": "[email protected]",
"url": "https://api.github.com/users/
gkellogg",
"avatar_url": "...",
"id": 46296,
"login": "gkellogg"
}
* json-ld-macros courtesy of Antonio Garrote

Macros

Transform information

Add @id to data

Other programatic
transformations
{
"type": "User",
"followers": 35,
"name": "Gregg Kellogg",
"email": "[email protected]",
"url": "https://api.github.com/users/
gkellogg",
"avatar_url": "...",
"id": 46296,
"login": "gkellogg"
}
* json-ld-macros courtesy of Antonio Garrote

Macros

Transform information

Add @id to data

Other programatic
transformations
{
"type": "User",
"followers": 35,
"name": "Gregg Kellogg",
"email": "[email protected]",
"url": "https://api.github.com/users/
gkellogg",
"avatar_url": "...",
"id": 46296,
"login": "gkellogg"
}
* json-ld-macros courtesy of Antonio Garrote
{
"https://api.github.com/users/*": {
"$": {
"@context": {
"foaf": "http://xmlns.com/foaf/0.1/",
"foaf:depiction": {"@type": "@id"},
"gh": "https://api.github.com/vocabulary#"
},
"@id": [{"f:valueof": "login"},
{"f:prefix": "http://github.com/"}],
"@ns": {
"ns:default": "gh",
"ns:replace": {"avatar_url": "foaf:depiction", "name":
"foaf:name"}
},
"@only": ["avatar_url", "name", "followers"],
"@type": ["gh:User", "foaf:Person"]
}
}
}
+

Macros

Transform information

Add @id to data

Other programatic
transformations
{
"type": "User",
"followers": 35,
"name": "Gregg Kellogg",
"email": "[email protected]",
"url": "https://api.github.com/users/
gkellogg",
"avatar_url": "...",
"id": 46296,
"login": "gkellogg"
}
* json-ld-macros courtesy of Antonio Garrote
{
"https://api.github.com/users/*": {
"$": {
"@context": {
"foaf": "http://xmlns.com/foaf/0.1/",
"foaf:depiction": {"@type": "@id"},
"gh": "https://api.github.com/vocabulary#"
},
"@id": [{"f:valueof": "login"},
{"f:prefix": "http://github.com/"}],
"@ns": {
"ns:default": "gh",
"ns:replace": {"avatar_url": "foaf:depiction", "name":
"foaf:name"}
},
"@only": ["avatar_url", "name", "followers"],
"@type": ["gh:User", "foaf:Person"]
}
}
}
+
{
"@context": {
"foaf": "http://xmlns.com/foaf/0.1/",
"foaf:depiction": {"@type": "@id"},
"gh": "https://api.github.com/
vocabulary#"
},
"@id": "https://api.github.com/users/
gkellogg",
"@type": ["gh:User", “foaf:Person”],
"foaf:name": "Gregg Kellogg",
"foaf:depiction": "http://...",
“gh:followers”: 35

The “LD” in JSON-LD

IRIs are first-class
citizens
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": "http://www.markus-lanthaler.com/"
}
http://greggkellogg.net/foaf
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
http://www.markus-lanthaler.com

The “LD” in JSON-LD

IRIs are first-class
citizens

Object definitions may
be referenced or
embedded
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": {
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
} {
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": "http://www.markus-lanthaler.com/"
}
http://greggkellogg.net/foaf
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
http://www.markus-lanthaler.com

RDF 
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": {
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
}

RDF 
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": {
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
}

RDF 
{
"@context": "http://json-ld.org/contexts/person",
"@id": "http://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg",
"knows": {
"@id": "http://www.markus-lanthaler.com/",
"@type": "Person",
"name": "Markus Lanthaler",
"knows" "http://greggkellogg.net/foaf#me"
}
}
@prefix: schema <http://schema.org/>
<http://greggkellogg.net/foaf#me> a schema:Person;
schema:name “Gregg Kellogg”;
shema:knows <http://www.markus-lanthaler.com/” .
<http://www.markus-lanthaler.com/> a schema:Person
schema:name “Markus Lanthaler”
schema:knows <http://greggkellogg.net/foaf#me> .

JSON-LD API
•compact – use minimal representation
using a supplied @context
•expand – expand to full form, removing
embedded @context definitions
•frame – query for JSON-LD
•fromRDF/toRDF

More Information
json-ld.org
w3c
JavaScript
Ruby
Python
Java
C++
PHP
Gregg Kellogg
@gkellogg
[email protected]
http://greggkellogg.net/