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.

JSON Referencing and Schema

11,025 views

Published on

Published in: Technology

JSON Referencing and Schema

  1. 1. Persistent Computing on the Web with JSON Schema and Referencing <ul><li>Kris Zyp </li></ul>
  2. 2. Overview <ul><li>JSON Referencing </li></ul><ul><li>JSON Schema </li></ul><ul><li>The possiblities... </li></ul>
  3. 3. JSON + Hyperlinks = JSON Referencing
  4. 4. JSON Referencing <ul><li>Cyclic </li></ul><ul><li>Multiple references </li></ul><ul><li>Cross-message references </li></ul><ul><li>Cross-site references </li></ul>http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo/
  5. 5. JSON Referencing (ID Based)‏ <ul><li>{ </li></ul><ul><ul><li>“ name”:”Kris Zyp”, </li></ul></ul><ul><ul><li>“ id”:”kriszyp”, “children”:[{“id”:”jennikazyp”,“name”:”Jennika Zyp”}], </li></ul></ul><ul><ul><li>“ spouse”:{ </li></ul></ul><ul><ul><ul><li>“ name”:”Nicole Zyp”, “spouse”:{“$ref”:”kriszyp”}, </li></ul></ul></ul><ul><ul><ul><li>“ children”:[{“$ref”:”jennikazyp”}] </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  6. 6. JSON Referencing (Path Based)‏ <ul><li>{ </li></ul><ul><ul><li>“ name”:”Kris Zyp”, “children”:[{“name”:”Jennika Zyp”}], </li></ul></ul><ul><ul><li>“ spouse”:{ </li></ul></ul><ul><ul><ul><li>“ name”:”Nicole Zyp”, “spouse”:{“$ref”:”#”}, </li></ul></ul></ul><ul><ul><ul><li>“ children”:{“$ref”:”#.children”} </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  7. 7. JSON Referencing (ID + Path)‏ <ul><li>{ </li></ul><ul><ul><li>“ name”:”Kris Zyp”, </li></ul></ul><ul><ul><li>“ id”:”kriszyp”, “children”:[{“name”:”Jennika Zyp”}], </li></ul></ul><ul><ul><li>“ friends”:[{“$ref”:”jesse#.spouse”}] </li></ul></ul><ul><li>} </li></ul>
  8. 8. JSON + Schema = JSON Schema
  9. 9. JSON Schema <ul><li>schema: </li></ul><ul><li>{&quot;description&quot;:&quot;A person&quot;, </li></ul><ul><li>&quot;type&quot;:&quot;object&quot;, </li></ul><ul><li>&quot;properties&quot;: </li></ul><ul><li>{&quot;name&quot;: {&quot;type&quot;:&quot;string&quot;}, </li></ul><ul><li>&quot;age&quot; : {&quot;type&quot;:&quot;integer&quot;, </li></ul><ul><li>&quot;maximum&quot;:125}} </li></ul><ul><li>} </li></ul><ul><li>instance: </li></ul><ul><li>{“name”:”Kris”, </li></ul><ul><li>“ age”:30} </li></ul>
  10. 10. JSON Schema <ul><li>Schema: </li></ul><ul><li>{&quot;description&quot;:&quot;A person&quot;, </li></ul><ul><li>&quot;type&quot;:&quot;object&quot;, </li></ul><ul><li>&quot;properties&quot;: </li></ul><ul><li>{&quot;name&quot;: {&quot;type&quot;:&quot;string&quot;}, </li></ul><ul><li>&quot;age&quot; : {&quot;type&quot;:&quot;integer&quot;, </li></ul><ul><li>&quot;maximum&quot;:125, “optional”:true}, “friends”: {“type”:”array”, “items”:{“type”:”object”}} } </li></ul><ul><li>} </li></ul><ul><li>instance: </li></ul><ul><li>{“name”:”Kris”, </li></ul><ul><li>“ friends”:[{“name”:”Nikki”}] </li></ul><ul><li>} </li></ul>
  11. 11. JSON Schema <ul><li>Schema: </li></ul><ul><li>{“type”:”array”, “items”:[{“type”:”string”},{“type”:”number”}] } </li></ul><ul><li>instance: </li></ul><ul><li>[“foo”,44] </li></ul>
  12. 12. JSON Schema <ul><li>Schema: </li></ul><ul><li>{&quot;description&quot;:&quot;A person&quot;, </li></ul><ul><li>&quot;type&quot;:[&quot;object&quot;,”string”] </li></ul><ul><li>} </li></ul><ul><li>instance: </li></ul><ul><li>“ foo” </li></ul><ul><li>instance: </li></ul><ul><li>{“prop”:3} </li></ul>
  13. 13. JSON Schema <ul><li>Schema: </li></ul><ul><li>{&quot;description&quot;:&quot;A person&quot;, </li></ul><ul><li>&quot;type&quot;:[&quot;object&quot;,”string”] </li></ul><ul><li>} </li></ul><ul><li>instance: </li></ul><ul><li>“ foo” </li></ul><ul><li>instance: </li></ul><ul><li>{“prop”:3} </li></ul>
  14. 14. JSON Schema <ul><li>schema: </li></ul><ul><li>{&quot;description&quot;:&quot;A person&quot;, </li></ul><ul><li>&quot;type&quot;:&quot;object&quot;, </li></ul><ul><li>&quot;properties&quot;: </li></ul><ul><li>{&quot;name&quot;: {&quot;type&quot;:&quot;string&quot;}, </li></ul><ul><li>&quot;gender&quot; : {&quot;type&quot;:&quot;string&quot;, </li></ul><ul><ul><ul><ul><li>&quot;enum”:[“male”,”female”]}}, </li></ul></ul></ul></ul><ul><li>“ additionalProperties”:false </li></ul><ul><li>} </li></ul><ul><li>instance: </li></ul><ul><li>{“name”:”Kris”, </li></ul><ul><li>“ gender”:”male”} </li></ul>
  15. 15. What can we do with these?
  16. 16. JSON Schema + JSON Referencing <ul><li>{&quot;description&quot;:&quot;A Social Person&quot;, “id”:”socialperson”, </li></ul><ul><li>&quot;type&quot;:&quot;object&quot;, </li></ul><ul><li>&quot;properties&quot;: </li></ul><ul><li>{&quot;name&quot;: {&quot;type&quot;:&quot;string&quot;}, </li></ul><ul><li>&quot;age&quot; : { </li></ul><ul><ul><ul><li>&quot;type&quot;:&quot;integer&quot;, </li></ul></ul></ul><ul><li>&quot;maximum&quot;:125 </li></ul><ul><ul><li>}, </li></ul></ul><ul><ul><li>&quot;friends&quot; : { </li></ul></ul><ul><ul><ul><li>“ type” : ”array”, </li></ul></ul></ul><ul><ul><ul><li>“ items” : {“$ref”:”socialperson”} </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>}, </li></ul><ul><li>“ extends”:{“$ref”:”person”} </li></ul><ul><li>} </li></ul>
  17. 17. JSON Referencing + REST <ul><li>Lazy loading - Generic clients can auto-load objects as necessary </li></ul><ul><li>Object identification can be used for saving state changes </li></ul>http://blog.medryx.org/2008/07/24/jsonreststore-overview/
  18. 18. JSON Referencing + REST <ul><li>GET /Person/3 </li></ul><ul><li>{ </li></ul><ul><li>“ name”:”Kris”, </li></ul><ul><li>“ friends”:[ </li></ul><ul><ul><li>{“$ref”:”4”}, </li></ul></ul><ul><ul><li>{“$ref”:”5”} </li></ul></ul><ul><li>] </li></ul><ul><li>} </li></ul>
  19. 19. JSON Referencing + JSON-RPC <ul><li>POST /person/kriszyp </li></ul><ul><li>{ </li></ul><ul><ul><li>“ method”:”addFriend”, </li></ul></ul><ul><ul><li>“ id”:”1”, </li></ul></ul><ul><ul><li>“ params”:[{“$ref”:”jessesmith”}] </li></ul></ul><ul><li>} </li></ul>
  20. 20. Applying data definitions to code
  21. 21. JSON Schema + Typed Code
  22. 22. JSON Schema Interfaces
  23. 23. JSON Schema Interface <ul><li>{&quot;description&quot;:&quot;A person&quot;, </li></ul><ul><li>&quot;type&quot;:&quot;object&quot;, </li></ul><ul><li>&quot;properties&quot;: </li></ul><ul><li>{&quot;name&quot;: {&quot;type&quot;:&quot;string&quot;} }, “methods”:{ “getName”:{“returns”:{“type”:”string”}, “params”:[]}, “setName”:{“params”:[{“type”:”string”}]}, } </li></ul><ul><li>} </li></ul>
  24. 24. Cross-site Referencing <ul><li>{ </li></ul><ul><ul><li>“ name”:”Kris Zyp”, </li></ul></ul><ul><ul><li>“ id”:”kriszyp”, </li></ul></ul><ul><ul><li>“ friends”:[ </li></ul></ul><ul><ul><ul><li>{“$ref”:” http://thezyps.com/person/nikki ”}, </li></ul></ul></ul><ul><ul><ul><li>{“$ref”:” http://social.com/user/33 ”} </li></ul></ul></ul><ul><ul><li>] </li></ul></ul><ul><li>} </li></ul>
  25. 25. Cross-site Typing
  26. 26. Mobile code (run anywhere)‏ <ul><li>Code can run anywhere </li></ul><ul><ul><li>Server JavaScript Environment </li></ul></ul><ul><ul><li>Browser JavaScript Environment </li></ul></ul><ul><li>Consistent persisted data structures across environments </li></ul>
  27. 27. Connecting and structuring data for the future JSON Schema and JSON Referencing

×