1/71
JSON-LD
BridgingthePresentandFutureWebs
Brian Sletten (!@bsletten)
08/17/2015
Speaker Qualifications
Specialize in next-generation technologies
Author of O'Reilly Videos on Hypermedia and Linking Data
Author of 'Resource-Oriented Architecture Patterns for Webs of Data'
Teaches and speaks internationally about REST, Semantic Web, Data Science,
Security, Visualization, Architecture
Worked in Defense, Finance, Retail, Hospitality, Video Game, Health Care,
Telecommunications and Publishing Industries
International Pop Recording Artist
·
·
·
·
·
·
3/71
Agenda
Introduction
Basic JSON-LD
Expansion, Compaction, Flattened
Development
Real World Uses
·
·
·
·
·
4/71
Introduction
6/71
Turtle
<https://w3id.org/people/bsletten>
a <http://xmlns.com/foaf/0.1/Person> ;
<http://xmlns.com/foaf/0.1/birthday>
"05-26" ;
<http://xmlns.com/foaf/0.1/name>
"Brian Sletten" .
7/71
Remote Turtle
> http get http://bosatsu.net/turtle/brian.ttl
<https://w3id.org/people/bsletten>
<http://xmlns.com/foaf/0.1/depiction>
<http://bosatsu.net/images/briansletten.jpg> .
8/71
Turtle
> rdfcat --out ttl facts.ttl http://bosatsu.net/turtle/brian.ttl
<https://w3id.org/people/bsletten>
a <http://xmlns.com/foaf/0.1/Person> ;
<http://xmlns.com/foaf/0.1/birthday>
"05-26" ;
<http://xmlns.com/foaf/0.1/depiction>
<http://bosatsu.net/images/briansletten.jpg> ;
<http://xmlns.com/foaf/0.1/name>
"Brian Sletten" .
9/71
10/71
Credit: LinkedData.org License: CC-BY-SA
11/71
12/71
13/71
Basic JSON-LD
JSON-LD Goals
100% Compatible with JSON
Zero Edits Where Possible
Bring Linked Data to Web Development
No knowledge of RDF required
Interoperable with RDF
Can be stored in JSON database engines
·
·
·
·
·
·
15/71
JSON
{
"name" : "Brian Sletten",
"birthday" : "05-26"
}
16/71
JSON-LD
{
"@context" : "http://bosatsu.net/context/basic.jsonld",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
17/71
Credit: danielcoy
License: CC BY-ND 2.0
JSON-LD Context
> http get http://bosatsu.net/context/basic.jsonld
HTTP/1.1 200 OK
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Content-Length: 130
Content-Type: application/ld+json
Date: Sun, 15 Feb 2015 21:08:17 GMT
ETag: "1049bf-82-50f267f82b680"
Last-Modified: Sun, 15 Feb 2015 20:41:46 GMT
Server: Apache/2.2.16 (Debian)
{
"@context": {
"birthday": "http://xmlns.com/foaf/0.1/birthday",
"name": "http://xmlns.com/foaf/0.1/name"
}
}
19/71
JSON-LD with Embedded Context
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday"
},
"name" : "Brian Sletten",
"birthday" : "05-26"
}
20/71
Generating Turtle From JSON-LD
> rdfcat --out ttl http://bosatsu.net/jsonld/basic.jsonld
[
<http://xmlns.com/foaf/0.1/birthday>
"05-26" ;
<http://xmlns.com/foaf/0.1/name>
"Brian Sletten"
] .
21/71
JSON-LD with Embedded Context and Id
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday"
},
"@id" : "https://w3id.org/people/bsletten",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
22/71
Generating Turtle From JSON-LD
> rdfcat --out ttl http://bosatsu.net/jsonld/basic.jsonld
<https://w3id.org/people/bsletten>
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten" .
23/71
Fetching Turtle
> http get http://bosatsu.net/turtle/brian.ttl
HTTP/1.1 200 OK
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Content-Length: 124
Content-Type: text/turtle
Date: Sun, 15 Feb 2015 22:58:49 GMT
ETag: "1049e7-7c-50f27daf231c0"
Last-Modified: Sun, 15 Feb 2015 22:18:55 GMT
Server: Apache/2.2.16 (Debian)
<https://w3id.org/people/bsletten>
<http://xmlns.com/foaf/0.1/depiction>
"http://bosatsu.net/images/briansletten.jpg" .
24/71
Merging JSON-LD and Turtle
> rdfcat --out ttl http://bosatsu.net/jsonld/basic.jsonld
http://bosatsu.net/turtle/brian.ttl
<https://w3id.org/people/bsletten>
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/depiction>
<http://bosatsu.net/images/briansletten.jpg> ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten" .
25/71
JSON-LD with Embedded Context
{
"@context" : {
"fullname" : "http://xmlns.com/foaf/0.1/name",
"dob" : "http://xmlns.com/foaf/0.1/birthday"
},
"fullname" : "Brian Sletten",
"dob" : "05-26"
}
<https://w3id.org/people/bsletten>
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten" .
26/71
HTTP Link Header (RFC5988)
> http get http://bosatsu.net/json/brian.json
HTTP/1.1 200 OK
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Content-Length: 56
Content-Type: application/json
Date: Sun, 15 Feb 2015 23:45:10 GMT
ETag: "1049ea-38-50f29083f5f80"
Last-Modified: Sun, 15 Feb 2015 23:43:10 GMT
Server: Apache/2.2.16 (Debian)
Link: <http://bosatsu.net/context/basic.jsonld>;
rel="http://www.w3.org/ns/json-ld#context";
type="application/ld+json"
{
"birthday": "05-26",
"name": "Brian Sletten"
}
27/71
JSON-LD Features
Internationalized Resource Identifiers (IRIs) for JSON objects
Key disambiguation
Make distributed JSON object references
Support I18N
Typed literals
Ability to express directed graphs
·
·
·
·
·
·
28/71
Terms
Short-hand string identifier
Can be expanded to an IRI or a blank node identifier
Minimal naming restrictions
·
·
·
Don't start with '@'
Cannot be a keyword
·
·
29/71
Node Objects
JSON object
Zero or more properties of a node
Not part of a @context
Does not contain @value, @list or @set keywords
·
·
·
·
30/71
Value Objects
JSON object
Used to associate types or languages with values
·
·
31/71
Node @type
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday"
},
"@type" : "http://xmlns.com/foaf/0.1/Person",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
[
a <http://xmlns.com/foaf/0.1/Person> ;
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten"
] .
32/71
Multiple Types
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday",
"Person" : "http://xmlns.com/foaf/0.1/Person",
"PhishFan" : "http://example.com/ns/PhishFan"
},
"@type" : ["Person", "PhishFan"],
"name" : "Brian Sletten",
"birthday" : "05-26"
}
[
a <http://xmlns.com/foaf/0.1/Person> ,
<http://example.com/ns/PhishFan> ;
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten"
] .
33/71
@vocab
{
"@context" : {
"@vocab" : "http://xmlns.com/foaf/0.1/"
},
"@type" : "Person",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
[
a <http://xmlns.com/foaf/0.1/Person> ;
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten"
] .
34/71
Identifying Identifiers
{
"@context" : {
"@vocab" : "http://xmlns.com/foaf/0.1/"
},
"@type" : "Person",
"name" : "Brian Sletten",
"birthday" : "05-26",
"homepage" : "http://bosatsu.net/"
}
[
a <http://xmlns.com/foaf/0.1/Person> ;
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/homepage> "http://bosatsu.net/" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten"
] .
35/71
Identifying Identifiers
{
"@context" : {
"@vocab" : "http://xmlns.com/foaf/0.1/",
"homepage": {
"@type" : "@id"
}
},
"@type" : "Person",
"name" : "Brian Sletten",
"birthday" : "05-26",
"homepage" : "http://bosatsu.net/"
}
[
a <http://xmlns.com/foaf/0.1/Person> ;
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/homepage> <http://bosatsu.net/> ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten"
] .
36/71
Value @type
{
"@context" : {
"foaf" : "http://xmlns.com/foaf/0.1/",
"name" : "foaf:name",
"birthday" : "foaf:birthday",
"xsd" : "http://www.w3.org/2001/XMLSchema#",
"ex" : "http://example.com/ns/",
"age" : { "@id" : "foaf:age", "@type" : "xsd:integer" }
},
"@type" : "ex:Dog",
"name" : "Loki of Asgard",
"birthday" : "05-30",
"age" : "3"
}
37/71
Value @type
@prefix ex: <http://example.com/ns/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
[
a ex:Dog ;
foaf:age 3 ;
foaf:birthday "05-30" ;
foaf:name "Loki of Asgard"
] .
38/71
Resolving Relative Identifiers
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday"
},
"@id" : "brian",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
<file:///Users/brian/src/jsonld/brian>
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten" .
39/71
@base
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday",
"@base" : "http://bosatsu.net/people/"
},
"@id" : "brian",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
<http://bosatsu.net/people/brian>
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten" .
40/71
Aliasing
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday",
"url" : "@id"
},
"url": "http://bosatsu.net/people/brian",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
<http://bosatsu.net/people/brian>
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten" .
41/71
@base + Aliasing
{
"@context" : {
"name" : "http://xmlns.com/foaf/0.1/name",
"birthday" : "http://xmlns.com/foaf/0.1/birthday",
"@base": "http://example.com/id/",
"eid" : "@id"
},
"eid": "12345",
"name" : "Brian Sletten",
"birthday" : "05-26"
}
<http://example.com/id/12345>
<http://xmlns.com/foaf/0.1/birthday> "05-26" ;
<http://xmlns.com/foaf/0.1/name> "Brian Sletten" .
42/71
Expansion, Compaction, Flattening
JSON-LD Document
{
"@context":
{
"name": "http://xmlns.com/foaf/0.1/name",
"homepage": {
"@id": "http://xmlns.com/foaf/0.1/homepage",
"@type": "@id"
}
},
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/"
}
44/71
JSON-LD Expanded Form
[
{
"http://xmlns.com/foaf/0.1/name": [
{ "@value": "Manu Sporny" }
],
"http://xmlns.com/foaf/0.1/homepage": [
{ "@id": "http://manu.sporny.org/" }
]
}
]
45/71
JSON-LD Document Compacted (Alt Context)
{
"@context":
{
"nom": "http://xmlns.com/foaf/0.1/name",
"page": {
"@id": "http://xmlns.com/foaf/0.1/homepage",
"@type": "@id"
}
},
"nom": "Manu Sporny",
"page": "http://manu.sporny.org/"
}
46/71
47/71
48/71
49/71
50/71
JSON-LD Document
{
"@context" : {
"@vocab" : "http://xmlns.com/foaf/0.1/"
},
"@id" : "https://w3id.org/people/bsletten",
"name" : "Brian Sletten",
"knows" : [
{ "@type" : "Person",
"name" : "Sean Cier" },
{ "@type" : "Person",
"name" : "Jeff Ricks" },
{ "@id" : "http://example.com/id/ironman",
"@type" : "Person",
"name" : "Malik Coates" }
]
}
51/71
JSON-LD Document Flattened
{ "@graph": [
{ "@id": "_:b0",
"@type": "http://xmlns.com/foaf/0.1/Person",
"http://xmlns.com/foaf/0.1/name": "Sean Cier" },
{ "@id": "_:b1",
"@type": "http://xmlns.com/foaf/0.1/Person",
"http://xmlns.com/foaf/0.1/name": "Jeff Ricks" },
{ "@id": "http://example.com/id/ironman",
"@type": "http://xmlns.com/foaf/0.1/Person",
"http://xmlns.com/foaf/0.1/name": "Malik Coates" },
{ "@id": "https://w3id.org/people/bsletten",
"http://xmlns.com/foaf/0.1/knows": [
{ "@id": "_:b0" },
{ "@id": "_:b1" },
{ "@id": "http://example.com/id/ironman" }
],
"http://xmlns.com/foaf/0.1/name": "Brian Sletten"
}]
}
52/71
Development
Credit: http://json-ld.org/playground/index.html
54/71
JSON-LD Tools
JavaScript : https://github.com/digitalbazaar/jsonld.js
Python
PHP
Ruby : https://github.com/ruby-rdf/json-ld/
Java : https://github.com/jsonld-java/jsonld-java
C# : https://github.com/NuGet/json-ld.net
·
·
https://github.com/digitalbazaar/pyld
https://github.com/RDFLib/rdflib-jsonld
·
·
·
https://github.com/digitalbazaar/php-json-ld
https://github.com/lanthaler/JsonLD
·
·
·
·
·
55/71
JSON-LD (Javascript)
var jsonld = require('jsonld');
var doc = {
"http://schema.org/name": "Manu Sporny",
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
"http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.pn
};
var context = {
"name": "http://schema.org/name",
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
"image": {"@id": "http://schema.org/image", "@type": "@id"}
};
// compact a document according to a particular context
jsonld.compact(doc, context, function(err, compacted) {
console.log(JSON.stringify(compacted, null, 2));
});
56/71
JSON-LD (Java)
// Open a valid json(-ld) input file
InputStream inputStream = new FileInputStream("input.json");
// Read the file into an Object (The type of this object will be a List, Ma
// Number or null depending on the root object in the file).
Object jsonObject = JsonUtils.fromInputStream(inputStream);
// Create a context JSON map containing prefixes and definitions
Map context = new HashMap();
// Customise context...
// Create an instance of JsonLdOptions with the standard JSON-
LD options
JsonLdOptions options = new JsonLdOptions();
// Customise options...
// Call whichever JSONLD function you want! (e.g. compact)
Object compact = JsonLdProcessor.compact(jsonObject, context, options);
// Print out the result (or don't, it's your call!)
System.out.println(JsonUtils.toPrettyString(compact));
57/71
Real World Uses
Wrapping Existing APIs
// RFC 6570 URI Templates
def url = "https://maps.googleapis.com/maps/api/geocode/json?
latlng=${lat},${lon}&key=${googleConfig.geocode.apikey}"
59/71
Embedded JSON-LD
<html>
<body>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EventReservation",
"reservationNumber": "IO12345",
"underName": {
"@type": "Person",
"name": "John Smith"
},
...
</script>
...
</html>
60/71
61/71
RSVPAction
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Event",
"name": "John's Birthday Party",
... information about the event ...
"action": {
"@type": "RsvpAction",
"actionHandler": {
"@type": "HttpActionHandler",
"url": "https://events-organizer.com/rsvp?eventId=123",
"method": "POST",
"requiredProperty": "rsvpStatus",
}
}
}
</script>
62/71
Responding...
POST /rsvp?eventId=123 HTTP/1.1
Host: events-organizer.com
Authorization: Bearer AbCdEf123456
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/1.0
(KHTML, like Gecko; Gmail Actions)
rsvpStatus=YES
63/71
64/71
<script type="application/ld+json">
[{
"@context" : "http://schema.org",
"@type" : "MusicEvent",
"name" : "Phish",
"startDate" : "2015-09-04T19:30",
"location" : {
"@type" : "Place",
"name" : "Dick's Sporting Goods Park",
"address" : "6000 Victory Way, Commerce City, CO, USA"
},
"offers" : {
"@type" : "Offer",
"url" : "http://www.altitudetickets.com/event/phish-sep-4-
3671/"
}
},
...
]
</script>
65/71
66/71
67/71
68/71
{
"@context": "https://w3id.org/identity/v1",
"id": "https://example.com/identities/bob",
"type": ["Identity", "Person"],
"name": "Bob Bobman",
"governmentId": "123-45-6789",
"birthdate": "1985-12-14",
"email": "bbob@example.com",
"mobileNumber": "12345678910",
"shippingAddress": {
"street": "372 Sumter Lane",
"city": "Blackrock",
"region": "Nevada",
"postalCode": "237842"
},
...
}
69/71
...
"credential": [{
"id": "http://ssa.us.gov/credentials/3732",
"type": "PassportCredential",
"claim": {
"id": "https://example.com/identities/bob",
"name": "Bob Bobman",
"birthdate": "1985-12-14",
"governmentId": "123-45-6789"
},
"expires": "2018-01-01",
"signature": {
"type": "GraphSignature2012",
"creator": "https://ssa.us.gov/keys/27",
"signature": "3780eyfh3q0fhhfiq3q9f8ahsidfhf29rhaish"
}
}, ... ]
}
70/71
Questions?
" brian@bosatsu.net
! @bsletten
+ http://tinyurl.com/bjs-gplus
$ bsletten

SmartData Webinar Slides JSON-LD

  • 1.
  • 2.
  • 3.
    Speaker Qualifications Specialize innext-generation technologies Author of O'Reilly Videos on Hypermedia and Linking Data Author of 'Resource-Oriented Architecture Patterns for Webs of Data' Teaches and speaks internationally about REST, Semantic Web, Data Science, Security, Visualization, Architecture Worked in Defense, Finance, Retail, Hospitality, Video Game, Health Care, Telecommunications and Publishing Industries International Pop Recording Artist · · · · · · 3/71
  • 4.
    Agenda Introduction Basic JSON-LD Expansion, Compaction,Flattened Development Real World Uses · · · · · 4/71
  • 5.
  • 6.
  • 7.
  • 8.
    Remote Turtle > httpget http://bosatsu.net/turtle/brian.ttl <https://w3id.org/people/bsletten> <http://xmlns.com/foaf/0.1/depiction> <http://bosatsu.net/images/briansletten.jpg> . 8/71
  • 9.
    Turtle > rdfcat --outttl facts.ttl http://bosatsu.net/turtle/brian.ttl <https://w3id.org/people/bsletten> a <http://xmlns.com/foaf/0.1/Person> ; <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/depiction> <http://bosatsu.net/images/briansletten.jpg> ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 9/71
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    JSON-LD Goals 100% Compatiblewith JSON Zero Edits Where Possible Bring Linked Data to Web Development No knowledge of RDF required Interoperable with RDF Can be stored in JSON database engines · · · · · · 15/71
  • 16.
    JSON { "name" : "BrianSletten", "birthday" : "05-26" } 16/71
  • 17.
    JSON-LD { "@context" : "http://bosatsu.net/context/basic.jsonld", "name": "Brian Sletten", "birthday" : "05-26" } 17/71
  • 18.
  • 19.
    JSON-LD Context > httpget http://bosatsu.net/context/basic.jsonld HTTP/1.1 200 OK Accept-Ranges: bytes Access-Control-Allow-Origin: * Content-Length: 130 Content-Type: application/ld+json Date: Sun, 15 Feb 2015 21:08:17 GMT ETag: "1049bf-82-50f267f82b680" Last-Modified: Sun, 15 Feb 2015 20:41:46 GMT Server: Apache/2.2.16 (Debian) { "@context": { "birthday": "http://xmlns.com/foaf/0.1/birthday", "name": "http://xmlns.com/foaf/0.1/name" } } 19/71
  • 20.
    JSON-LD with EmbeddedContext { "@context" : { "name" : "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday" }, "name" : "Brian Sletten", "birthday" : "05-26" } 20/71
  • 21.
    Generating Turtle FromJSON-LD > rdfcat --out ttl http://bosatsu.net/jsonld/basic.jsonld [ <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" ] . 21/71
  • 22.
    JSON-LD with EmbeddedContext and Id { "@context" : { "name" : "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday" }, "@id" : "https://w3id.org/people/bsletten", "name" : "Brian Sletten", "birthday" : "05-26" } 22/71
  • 23.
    Generating Turtle FromJSON-LD > rdfcat --out ttl http://bosatsu.net/jsonld/basic.jsonld <https://w3id.org/people/bsletten> <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 23/71
  • 24.
    Fetching Turtle > httpget http://bosatsu.net/turtle/brian.ttl HTTP/1.1 200 OK Accept-Ranges: bytes Access-Control-Allow-Origin: * Content-Length: 124 Content-Type: text/turtle Date: Sun, 15 Feb 2015 22:58:49 GMT ETag: "1049e7-7c-50f27daf231c0" Last-Modified: Sun, 15 Feb 2015 22:18:55 GMT Server: Apache/2.2.16 (Debian) <https://w3id.org/people/bsletten> <http://xmlns.com/foaf/0.1/depiction> "http://bosatsu.net/images/briansletten.jpg" . 24/71
  • 25.
    Merging JSON-LD andTurtle > rdfcat --out ttl http://bosatsu.net/jsonld/basic.jsonld http://bosatsu.net/turtle/brian.ttl <https://w3id.org/people/bsletten> <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/depiction> <http://bosatsu.net/images/briansletten.jpg> ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 25/71
  • 26.
    JSON-LD with EmbeddedContext { "@context" : { "fullname" : "http://xmlns.com/foaf/0.1/name", "dob" : "http://xmlns.com/foaf/0.1/birthday" }, "fullname" : "Brian Sletten", "dob" : "05-26" } <https://w3id.org/people/bsletten> <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 26/71
  • 27.
    HTTP Link Header(RFC5988) > http get http://bosatsu.net/json/brian.json HTTP/1.1 200 OK Accept-Ranges: bytes Access-Control-Allow-Origin: * Content-Length: 56 Content-Type: application/json Date: Sun, 15 Feb 2015 23:45:10 GMT ETag: "1049ea-38-50f29083f5f80" Last-Modified: Sun, 15 Feb 2015 23:43:10 GMT Server: Apache/2.2.16 (Debian) Link: <http://bosatsu.net/context/basic.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" { "birthday": "05-26", "name": "Brian Sletten" } 27/71
  • 28.
    JSON-LD Features Internationalized ResourceIdentifiers (IRIs) for JSON objects Key disambiguation Make distributed JSON object references Support I18N Typed literals Ability to express directed graphs · · · · · · 28/71
  • 29.
    Terms Short-hand string identifier Canbe expanded to an IRI or a blank node identifier Minimal naming restrictions · · · Don't start with '@' Cannot be a keyword · · 29/71
  • 30.
    Node Objects JSON object Zeroor more properties of a node Not part of a @context Does not contain @value, @list or @set keywords · · · · 30/71
  • 31.
    Value Objects JSON object Usedto associate types or languages with values · · 31/71
  • 32.
    Node @type { "@context" :{ "name" : "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday" }, "@type" : "http://xmlns.com/foaf/0.1/Person", "name" : "Brian Sletten", "birthday" : "05-26" } [ a <http://xmlns.com/foaf/0.1/Person> ; <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" ] . 32/71
  • 33.
    Multiple Types { "@context" :{ "name" : "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday", "Person" : "http://xmlns.com/foaf/0.1/Person", "PhishFan" : "http://example.com/ns/PhishFan" }, "@type" : ["Person", "PhishFan"], "name" : "Brian Sletten", "birthday" : "05-26" } [ a <http://xmlns.com/foaf/0.1/Person> , <http://example.com/ns/PhishFan> ; <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" ] . 33/71
  • 34.
    @vocab { "@context" : { "@vocab": "http://xmlns.com/foaf/0.1/" }, "@type" : "Person", "name" : "Brian Sletten", "birthday" : "05-26" } [ a <http://xmlns.com/foaf/0.1/Person> ; <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" ] . 34/71
  • 35.
    Identifying Identifiers { "@context" :{ "@vocab" : "http://xmlns.com/foaf/0.1/" }, "@type" : "Person", "name" : "Brian Sletten", "birthday" : "05-26", "homepage" : "http://bosatsu.net/" } [ a <http://xmlns.com/foaf/0.1/Person> ; <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/homepage> "http://bosatsu.net/" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" ] . 35/71
  • 36.
    Identifying Identifiers { "@context" :{ "@vocab" : "http://xmlns.com/foaf/0.1/", "homepage": { "@type" : "@id" } }, "@type" : "Person", "name" : "Brian Sletten", "birthday" : "05-26", "homepage" : "http://bosatsu.net/" } [ a <http://xmlns.com/foaf/0.1/Person> ; <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/homepage> <http://bosatsu.net/> ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" ] . 36/71
  • 37.
    Value @type { "@context" :{ "foaf" : "http://xmlns.com/foaf/0.1/", "name" : "foaf:name", "birthday" : "foaf:birthday", "xsd" : "http://www.w3.org/2001/XMLSchema#", "ex" : "http://example.com/ns/", "age" : { "@id" : "foaf:age", "@type" : "xsd:integer" } }, "@type" : "ex:Dog", "name" : "Loki of Asgard", "birthday" : "05-30", "age" : "3" } 37/71
  • 38.
    Value @type @prefix ex:<http://example.com/ns/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . [ a ex:Dog ; foaf:age 3 ; foaf:birthday "05-30" ; foaf:name "Loki of Asgard" ] . 38/71
  • 39.
    Resolving Relative Identifiers { "@context": { "name" : "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday" }, "@id" : "brian", "name" : "Brian Sletten", "birthday" : "05-26" } <file:///Users/brian/src/jsonld/brian> <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 39/71
  • 40.
    @base { "@context" : { "name": "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday", "@base" : "http://bosatsu.net/people/" }, "@id" : "brian", "name" : "Brian Sletten", "birthday" : "05-26" } <http://bosatsu.net/people/brian> <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 40/71
  • 41.
    Aliasing { "@context" : { "name": "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday", "url" : "@id" }, "url": "http://bosatsu.net/people/brian", "name" : "Brian Sletten", "birthday" : "05-26" } <http://bosatsu.net/people/brian> <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 41/71
  • 42.
    @base + Aliasing { "@context": { "name" : "http://xmlns.com/foaf/0.1/name", "birthday" : "http://xmlns.com/foaf/0.1/birthday", "@base": "http://example.com/id/", "eid" : "@id" }, "eid": "12345", "name" : "Brian Sletten", "birthday" : "05-26" } <http://example.com/id/12345> <http://xmlns.com/foaf/0.1/birthday> "05-26" ; <http://xmlns.com/foaf/0.1/name> "Brian Sletten" . 42/71
  • 43.
  • 44.
    JSON-LD Document { "@context": { "name": "http://xmlns.com/foaf/0.1/name", "homepage":{ "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }, "name": "Manu Sporny", "homepage": "http://manu.sporny.org/" } 44/71
  • 45.
    JSON-LD Expanded Form [ { "http://xmlns.com/foaf/0.1/name":[ { "@value": "Manu Sporny" } ], "http://xmlns.com/foaf/0.1/homepage": [ { "@id": "http://manu.sporny.org/" } ] } ] 45/71
  • 46.
    JSON-LD Document Compacted(Alt Context) { "@context": { "nom": "http://xmlns.com/foaf/0.1/name", "page": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }, "nom": "Manu Sporny", "page": "http://manu.sporny.org/" } 46/71
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
    JSON-LD Document { "@context" :{ "@vocab" : "http://xmlns.com/foaf/0.1/" }, "@id" : "https://w3id.org/people/bsletten", "name" : "Brian Sletten", "knows" : [ { "@type" : "Person", "name" : "Sean Cier" }, { "@type" : "Person", "name" : "Jeff Ricks" }, { "@id" : "http://example.com/id/ironman", "@type" : "Person", "name" : "Malik Coates" } ] } 51/71
  • 52.
    JSON-LD Document Flattened {"@graph": [ { "@id": "_:b0", "@type": "http://xmlns.com/foaf/0.1/Person", "http://xmlns.com/foaf/0.1/name": "Sean Cier" }, { "@id": "_:b1", "@type": "http://xmlns.com/foaf/0.1/Person", "http://xmlns.com/foaf/0.1/name": "Jeff Ricks" }, { "@id": "http://example.com/id/ironman", "@type": "http://xmlns.com/foaf/0.1/Person", "http://xmlns.com/foaf/0.1/name": "Malik Coates" }, { "@id": "https://w3id.org/people/bsletten", "http://xmlns.com/foaf/0.1/knows": [ { "@id": "_:b0" }, { "@id": "_:b1" }, { "@id": "http://example.com/id/ironman" } ], "http://xmlns.com/foaf/0.1/name": "Brian Sletten" }] } 52/71
  • 53.
  • 54.
  • 55.
    JSON-LD Tools JavaScript :https://github.com/digitalbazaar/jsonld.js Python PHP Ruby : https://github.com/ruby-rdf/json-ld/ Java : https://github.com/jsonld-java/jsonld-java C# : https://github.com/NuGet/json-ld.net · · https://github.com/digitalbazaar/pyld https://github.com/RDFLib/rdflib-jsonld · · · https://github.com/digitalbazaar/php-json-ld https://github.com/lanthaler/JsonLD · · · · · 55/71
  • 56.
    JSON-LD (Javascript) var jsonld= require('jsonld'); var doc = { "http://schema.org/name": "Manu Sporny", "http://schema.org/url": {"@id": "http://manu.sporny.org/"}, "http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.pn }; var context = { "name": "http://schema.org/name", "homepage": {"@id": "http://schema.org/url", "@type": "@id"}, "image": {"@id": "http://schema.org/image", "@type": "@id"} }; // compact a document according to a particular context jsonld.compact(doc, context, function(err, compacted) { console.log(JSON.stringify(compacted, null, 2)); }); 56/71
  • 57.
    JSON-LD (Java) // Opena valid json(-ld) input file InputStream inputStream = new FileInputStream("input.json"); // Read the file into an Object (The type of this object will be a List, Ma // Number or null depending on the root object in the file). Object jsonObject = JsonUtils.fromInputStream(inputStream); // Create a context JSON map containing prefixes and definitions Map context = new HashMap(); // Customise context... // Create an instance of JsonLdOptions with the standard JSON- LD options JsonLdOptions options = new JsonLdOptions(); // Customise options... // Call whichever JSONLD function you want! (e.g. compact) Object compact = JsonLdProcessor.compact(jsonObject, context, options); // Print out the result (or don't, it's your call!) System.out.println(JsonUtils.toPrettyString(compact)); 57/71
  • 58.
  • 59.
    Wrapping Existing APIs //RFC 6570 URI Templates def url = "https://maps.googleapis.com/maps/api/geocode/json? latlng=${lat},${lon}&key=${googleConfig.geocode.apikey}" 59/71
  • 60.
    Embedded JSON-LD <html> <body> <script type="application/ld+json"> { "@context":"http://schema.org", "@type": "EventReservation", "reservationNumber": "IO12345", "underName": { "@type": "Person", "name": "John Smith" }, ... </script> ... </html> 60/71
  • 61.
  • 62.
    RSVPAction <script type="application/ld+json"> { "@context": "http://schema.org", "@type":"Event", "name": "John's Birthday Party", ... information about the event ... "action": { "@type": "RsvpAction", "actionHandler": { "@type": "HttpActionHandler", "url": "https://events-organizer.com/rsvp?eventId=123", "method": "POST", "requiredProperty": "rsvpStatus", } } } </script> 62/71
  • 63.
    Responding... POST /rsvp?eventId=123 HTTP/1.1 Host:events-organizer.com Authorization: Bearer AbCdEf123456 Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/1.0 (KHTML, like Gecko; Gmail Actions) rsvpStatus=YES 63/71
  • 64.
  • 65.
    <script type="application/ld+json"> [{ "@context" :"http://schema.org", "@type" : "MusicEvent", "name" : "Phish", "startDate" : "2015-09-04T19:30", "location" : { "@type" : "Place", "name" : "Dick's Sporting Goods Park", "address" : "6000 Victory Way, Commerce City, CO, USA" }, "offers" : { "@type" : "Offer", "url" : "http://www.altitudetickets.com/event/phish-sep-4- 3671/" } }, ... ] </script> 65/71
  • 66.
  • 67.
  • 68.
  • 69.
    { "@context": "https://w3id.org/identity/v1", "id": "https://example.com/identities/bob", "type":["Identity", "Person"], "name": "Bob Bobman", "governmentId": "123-45-6789", "birthdate": "1985-12-14", "email": "bbob@example.com", "mobileNumber": "12345678910", "shippingAddress": { "street": "372 Sumter Lane", "city": "Blackrock", "region": "Nevada", "postalCode": "237842" }, ... } 69/71
  • 70.
    ... "credential": [{ "id": "http://ssa.us.gov/credentials/3732", "type":"PassportCredential", "claim": { "id": "https://example.com/identities/bob", "name": "Bob Bobman", "birthdate": "1985-12-14", "governmentId": "123-45-6789" }, "expires": "2018-01-01", "signature": { "type": "GraphSignature2012", "creator": "https://ssa.us.gov/keys/27", "signature": "3780eyfh3q0fhhfiq3q9f8ahsidfhf29rhaish" } }, ... ] } 70/71
  • 71.
    Questions? " brian@bosatsu.net ! @bsletten +http://tinyurl.com/bjs-gplus $ bsletten