($and/ <== DO NOT REMOVE - switch for preventing MathML interpretation of dollar signs on this page)

About

This page is a proposal for how to adapt the XDI graph model to developer-friendly JSON using the same mapping pattern that JSON-LD uses to adapt the RDF graph model to developer-friendly JSON.

Change Log

The JSON-LD Model

The following section is quoted from the Wikipedia page on JSON-LD.

From Wikipedia

JSON-LD, or JavaScript Object Notation for Linked Data, is a method of encoding Linked Data using JSON. It's design goal was to require as little effort as possible from developers to transform their existing JSON to JSON-LD. This would allow data to be serialized in a way that is similar to traditional JSON. JSON-LD is now a World Wide Web Consortium Recommendation that was developed by the JSON for Linking Data Community Group before it has been transferred to the RDF Working Group for review, improvement, and standardization.

JSON-LD is designed around the concept of a "context" to provide additional mappings from JSON to an RDF model. The context links object properties in a JSON document to concepts in an ontology. In order to map the JSON-LD syntax to RDF, JSON-LD allows values to be coerced to a specified type or to be tagged with a language. A context can be embedded directly in a JSON-LD document or put into a separate file and referenced from different documents (from traditional JSON documents via an HTTP Link header).

Following is an example of a context object that is defined inline:

{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "homepage": {
      "@id": "http://xmlns.com/foaf/0.1/workplaceHomepage",
      "@type": "@id"
    },
    "Person": "http://xmlns.com/foaf/0.1/Person"
  },
  "@id": "http://me.example.com",
  "@type": "Person",
  "name": "John Smith",
  "homepage": "http://www.example.com/"
}

The example above describes a person, based on the FOAF vocabulary. First, the two JSON properties name and homepage and the type person are mapped to concepts in the FOAF vocabulary and the value of the homepage property is specified to be of the type @id, i.e., it is specified to be an IRI in the context definition. Based on the RDF model, this allows the person described in the document to be unambiguously identified by an IRI.

How @context Works

As described above, the JSON-LD @context keyword is the heart of JSON-LD. As a JSON object, it defines a mapping from a JSON object key (which JSON-LD calls a term) to an IRI that identifies the equivalent term in an RDF ontology. An @context map may be defined inline, as shown in the example above, or it be referenced. Following are more detailed examples from section 5.1 of the the JSON-LD spec.

Defining an @context Inline

{
  "@context":
  {
    "name": "http://schema.org/name",  ← This means that 'name' is shorthand for 'http://schema.org/name' 
    "image": {
      "@id": "http://schema.org/image",  ← This means that 'image' is shorthand for 'http://schema.org/image' 
      "@type": "@id"  ← This means that a string value associated with 'image' should be interpreted as an identifier that is an IRI 
    },
    "homepage": {
      "@id": "http://schema.org/url",  ← This means that 'homepage' is shorthand for 'http://schema.org/url' 
      "@type": "@id"  ← This means that a string value associated with 'homepage' should be interpreted as an identifier that is an IRI 
    }
  }
}

Defining an @context By Reference

{
  "@context": "http://json-ld.org/contexts/person.jsonld",
  "name": "Manu Sporny",
  "homepage": "http://manu.sporny.org/",
  "image": "http://manu.sporny.org/images/manu.png"
}

The JXD Model

The thesis of JXD is that XDI can become much more accessible to JSON developers by defining a JSON-friendly format following the same pattern as JSON-LD, i.e., by mapping JSON terms to XDI semantic graph nodes.

In JXD, this mapping would always be to XDI addresses instead of to IRIs. Other than that, the only difference might be that the JXD keywords are a superset of the JSON-LD keywords due to the additional power of the XDI graph model.

It is proposed that JXD uses the same keywords as JSON-LD except the mapping declaration MUST use the keyword @xdi. As with JSON-LD, JXD can define an @xdi mapping inline or via reference. Following are examples of both.

Example #1: Defining an @xdi Mapping Inline

{
  "@xdi": {
    "name": "<#name>",
    "homepage": {
      "@id": "<#homepage>",
      "@type": "$iri"
    },
    "friend": {
      "@id": "#friend",
      "@type": "@id"
    }
  },
  "@id": "=!:uuid:33ad7beb-1abc-4a26-b892-466df4379a51",
  "@type": "#person",
  "name": "John Smith",
  "homepage": "http://www.example.com/",
  "friend": [ "=!:uuid:0a81d660-722d-4827-b80a-2c9e67ada041" ]
}

Example #2: Defining an @xdi Mapping By Reference

{
  "@xdi": "http://xdi.example.org/contexts/person.jxd",
  "@id": "=!:uuid:33ad7beb-1abc-4a26-b892-466df4379a51",
  "@type": "#person",
  "name": "John Smith",
  "homepage": "http://www.example.com/",
  "friend": [ "=!:uuid:0a81d660-722d-4827-b80a-2c9e67ada041" ]
}

Standard JXD Mappings

The following @xdi mappings are "built into the XDI specifications" and can be used by any JXD instance document without explicit reference:

Base @xdi mapping:

{
        "is": { "@id": "$is", "@type": "@id" },
        "ref": { "@id": "$ref", "@type": "@id" },
        "rep": { "@id": "$rep", "@type": "@id" }
}

Profile @xdi mapping:

{
        "name": { "@id": "<#name>" },
        "email": { "@id": "<#email>" },
        "friend": { "@id": "#friend", "@type": "@id" }
}

Message @xdi mapping:

{
        "msg": { "@id": "$msg", "@type": "@id" },
        "get": { "@id": "$get", "@type": "@id" },
        "set": { "@id": "$set", "@type": "@id" },
        "del": { "@id": "$del", "@type": "@id" },
        "get-graph": { "@id": "$get", "@type": "@graph" },
        "set-graph": { "@id": "$set", "@type": "@graph" },
        "del-graph": { "@id": "$del", "@type": "@graph" },
        "from": { "@id": "$from", "@type": "@id" },
        "to": { "@id": "$to", "@type": "@id" },
        "do": { "@id": "$do", "@type": "@id" }
}

Link contract @xdi mapping:

{
        "contract": { "@id": "$contract", "@type": "@id" },
        "do": { "@id": "$do", "@type": "@id" },
        "if": { "@id": "$if", "@type": "@id" },
        "not": { "@id": "$not", "@type": "@id" },
        "and": { "@id": "$and", "@type": "@id" },
        "or": { "@id": "$or", "@type": "@id" },
        "if-and": { "@id": "$if$and", "@type": "@id" },
        "if-or": { "@id": "$if$or", "@type": "@id" },
        "true": { "@id": "$true", "@type": "@graph" },
        "false": { "@id": "$false", "@type": "@graph" },
        "msg-variable": { "@id": "{$msg}", "@type": "@id" },
        "from-variable": { "@id": "{$from}", "@type": "@id" },
        "to-variable": { "@id": "{$to}", "@type": "@id" },
        "sigvalid": { "@id": "<$sig><$valid>" }
}

JXD Examples

Message example:

=markus[$msg]*!:uuid:1234/$from/(=markus)
=markus[$msg]*!:uuid:1234/$to/(=drummond)
=markus[$msg]*!:uuid:1234/$do/(=drummond/=markus)$do
(=markus[$msg]*!:uuid:1234$do/$set)=markus<#name>/&/"Markus Sabadello"
(=markus[$msg]*!:uuid:1234$do/$set)=markus<#email>/&/"markus@danubetech.com"
(=markus[$msg]*!:uuid:1234$do/$set)=markus/#friend/=drummond
=markus[$msg]*!:uuid:1234$do/$get/=markus<#name>
=markus[$msg]*!:uuid:1234$do/$get/=markus<#email>

{
    "@xdi": {
      "msg:uuid:1234": {
        "@id": "[$msg]*!:uuid:1234",
        "@type": "@id"
      }
    },
    "@id": "=markus",
    "msg:uuid:1234": {
      "from": [
        "(=markus)"
      ],
      "to": [
        "(=drummond)"
      ],
      "contract": [
        "(=drummond/=markus)$contract"
      ],
      "do": {
        "get": [
          "=markus<#name>",
          "=markus<#email>"
        ],
        "set-graph": {
          "@type": "@graph",
          "=markus": {
            "name": "Markus Sabadello",
            "email": "markus@danubetech.com",
            "friend": [
              "=drummond"
            ]
          }
        }
      }
    }
}

Link contract example:

(=markus/=drummond)$contract$do/$get/=markus<#email>
(=markus/=drummond)($contract$if$and/$true){$from}/$is/=drummond
(=markus/=drummond)($contract$if$and/$true){$msg}<$sig><$valid>/&/true

{
    "@id": "=markus",
    "=drummond": {
      "@type": "@graph",
      "contract": {
        "if-and": {
          "true": {
            "@type": "@graph",
            "from-variable": {
              "is": [
                "=drummond"
              ]
            },
            "msg-variable": {
              "sigvalid": true
            }
          }
        },
        "do": {
          "get": [
            "=markus<#email>"
          ]
        }
      }
    }
}

Open Questions for Defining JXD

  1. Should JXD be a superset of JSON-LD? We should review section 3.3 Syntax Tokens and Keywords of the JSON-LD spec and ask the following questions:

    1. Do all of these keywords also apply to JXD?
    2. If some do not, why not?
    3. If some apply differently, how are they different and why?
  2. What other new keywords are needed for XDI-specific concepts, e.g.:
    1. Peer graphs
    2. Inner graphs
    3. Equivalence relations
    4. Link contracts

JsonXdiMapping (last edited 2016-11-10 10:48:06 by peacekeeper)