Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SmartData Webinar Slides JSON-LD

1,626 views

Published on

The Semantic Web and its related technologies provide an incredibly powerful model for driving the cost of data integration down to nearly zero. So, how do we help developers who are overwhelmed, frightened or annoyed by its data models and formats?

Everyone can have semantically rich, interoperable data and modern application tools, frameworks and user interfaces. There is a surprisingly simple mechanism by which “normal” developers can benefit from the power of the Semantic Web and the latter's developers can integrate with the panoply of tools and toys under constant development by the former.

The trick is JSON-LD. A simple, but deliberately designed extension to JSON that bridges both worlds and is finding its way into many other uses by the likes of Google and GitHub. You will learn about:

the JSON-LD format
how to frame, sign and validate it
how to convert it to/from RDF
how to describe Hypermedia systems with Hydra and JSON-LD
how to embed and consume JSON-LD in HTML documents
how JSON-LD is being used in a variety of mass market ways

Published in: Data & Analytics
  • Be the first to comment

SmartData Webinar Slides JSON-LD

  1. 1. 1/71
  2. 2. JSON-LD BridgingthePresentandFutureWebs Brian Sletten (!@bsletten) 08/17/2015
  3. 3. 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
  4. 4. Agenda Introduction Basic JSON-LD Expansion, Compaction, Flattened Development Real World Uses · · · · · 4/71
  5. 5. Introduction
  6. 6. 6/71
  7. 7. 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
  8. 8. 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
  9. 9. 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. 10. 10/71
  11. 11. Credit: LinkedData.org License: CC-BY-SA 11/71
  12. 12. 12/71
  13. 13. 13/71
  14. 14. Basic JSON-LD
  15. 15. 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
  16. 16. JSON { "name" : "Brian Sletten", "birthday" : "05-26" } 16/71
  17. 17. JSON-LD { "@context" : "http://bosatsu.net/context/basic.jsonld", "name" : "Brian Sletten", "birthday" : "05-26" } 17/71
  18. 18. Credit: danielcoy License: CC BY-ND 2.0
  19. 19. 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
  20. 20. 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
  21. 21. 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
  22. 22. 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
  23. 23. 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
  24. 24. 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
  25. 25. 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
  26. 26. 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
  27. 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. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. Value Objects JSON object Used to associate types or languages with values · · 31/71
  32. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 43. Expansion, Compaction, Flattening
  44. 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. 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. 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. 47. 47/71
  48. 48. 48/71
  49. 49. 49/71
  50. 50. 50/71
  51. 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. 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. 53. Development
  54. 54. Credit: http://json-ld.org/playground/index.html 54/71
  55. 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. 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. 57. 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
  58. 58. Real World Uses
  59. 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. 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. 61. 61/71
  62. 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. 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. 64. 64/71
  65. 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. 66. 66/71
  67. 67. 67/71
  68. 68. 68/71
  69. 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. 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. 71. Questions? " brian@bosatsu.net ! @bsletten + http://tinyurl.com/bjs-gplus $ bsletten

×