JSON-LD: Linked Data for Web Apps

gkellogg1 3,454 views 27 slides Jul 11, 2012
Slide 1
Slide 1 of 27
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

About This Presentation

No description available for this slideshow.


Slide Content

JSON-LD
Linked Data for Web Apps
Gregg Kellogg
[email protected]
@gkellogg
Tuesday, July 10, 12

Introducing JSON-LD
JSON-based syntax to express linked data
@context
@id
@type
@value
@language
@graph
@list
@set
Tuesday, July 10, 12
JSON-LD brings a standard representation for expressing entity-value relationships using a
few standard keywords and a consistent organizational structure for JSON Objects.
•Objects represent entities, with keys acting as properties.
•Properties always expand to full IRIs.
•Arrays express a set of values associated with a property, unordered by default.
•Order expressed in @context or as an expanded value representation.
•Values are Object, string or native, with standard XSD representations for native types.
•Expanded form allows for more datatype and language variations.

Self-describing Messages

Give objects types
(@type)
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"knows": {"@id": "schema:knows", "@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"
}
Tuesday, July 10, 12
The @type key gives an object with one or more types, described with an IRI.
The @context provides a way to express IRIs as simple terms, and allows values to be typed.

Self-describing Messages

Give objects types
(@type)

Associate properties
with IRIs
{
"@context": {
"schema": "http://schema.org/",
"Person": "schema:Person",
"knows": {"@id": "schema:knows", "@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"
}
Tuesday, July 10, 12

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",
"knows": {"@id": "schema:knows", "@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"
}
Tuesday, July 10, 12

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",
"knows": {"@id": "schema:knows", "@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"
}
Tuesday, July 10, 12

RDF Mapping
{
"@context": {
"schema": "http://schema.org/",
"schema:knows": {"@type": "@id"},
"schema:image": {"@type": "@id"},
"schema:url": {"@type": "@id"}
}
}
{
"@context": "http://example.com/context.jsonld",
"@type": "schema:Person",
"schema:image":
"http://localhost:9393/examples/schema.org/janedoe.jpg",
"schema:knows": [
"http://www.xyz.edu/students/alicejones.html",
"http://www.xyz.edu/students/bobsmith.html"
],
"schema:name": "Jane Doe",
"schema:url": "http://www.janedoe.com"
}
@prefix schema: <http://schema.org/> .
[ a schema:Person;
schema:image
<http://localhost:9393/examples/schema.org/janedoe.jpg >;
schema:knows
<http://www.xyz.edu/students/alicejones.html>,
<http://www.xyz.edu/students/bobsmith.html>;
schema:name “Jane Doe”;
schema:url <http://www.janedoe.com>
] .
Tuesday, July 10, 12

History

2010 – Started as a way to project from the RDFa API

Developers want solutions to work within HTML
applications

Desire for JSON-idiomatic way of representing RDF
(Linked Data)

Adapt existing JSON APIs to Linked Data
Tuesday, July 10, 12

History
•2011 – W3C Community Group launched
•Broad Participation
•Separation of Syntax from API
•Proposed to W3C RDF 1.1 Working
Group
Tuesday, July 10, 12

History
•2012 – RDF WG abandons other JSON
serialization efforts (RDF/JSON)
•JSON-LD accepted as official work item
•Community Group drafts final report
•RDF WG to publish JSON-LD (Syntax
and API) as FPWD
Tuesday, July 10, 12

Language Principles
Tuesday, July 10, 12

{
"@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
Tuesday, July 10, 12

{
"@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
Tuesday, July 10, 12

{
"@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"]
}]
}
Tuesday, July 10, 12

{
"@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/"}
}
Tuesday, July 10, 12


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/"
}
Tuesday, July 10, 12


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/"
}
Tuesday, July 10, 12


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"
}
}
Tuesday, July 10, 12
Subject reference identifies an object with @id in the same document, or references an
external document (Linked Data).


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"
}
}
Tuesday, July 10, 12
Subject reference identifies an object with @id in the same document, or references an
external document (Linked Data).


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/"
}
Tuesday, July 10, 12


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/"
}
Tuesday, July 10, 12

•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
Tuesday, July 10, 12

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"
}
Tuesday, July 10, 12
Normal JSON can be made JSON-LD by adding an external context through an HTTP link
relation.

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
Tuesday, July 10, 12

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
Tuesday, July 10, 12

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
Tuesday, July 10, 12

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