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

About

This is a proposal for serializing an XDI graph in JSON using a key-value structure.

Change Log

Motivations/Requirements

See the overall motivations on Serialization Formats. For XDI Flat Serialization, the motivation is to have a JSON serialization format optimized for key-value data storage and access.

XDI Flat Serialization Rules

Following are the proposed rules for serializing an XDI graph in a flat key/value format in JSON:

  1. A valid XDI flat serialization document MUST be a valid JSON document according to RFC 4627 with the MIME type specified in SerializationFormats.

  2. The XDI graph MUST be serialized as a single top-level JSON object ("peer root object").
  3. Every top-level XDI statement in the graph MUST be serialized as a key-value pair ("statement object") contained within the peer root object.
  4. For every statement object, the string representing the key MUST consist of the first two segments of the XDI statement, i.e., the XDI addresses representing the XDI subject and XDI predicate.
    1. The key MUST include the forward slash separating the XDI subject and XDI predicate.
    2. The key MUST NOT include a trailing slash after the XDI predicate.
  5. If the XDI predicate ends with &, representing a literal arc, the value following the key MUST be a JSON value representing the XDI literal. All native JSON data types are supported except null (which is represented by the absence of an XDI value context).

  6. If the XDI predicate is (), representing a contextual arc, then the value following the key MUST be a JSON array of JSON strings representing the XDI addresses of each subcontext.

  7. If the XDI predicate is any other XDI address (and thus represents a relational arc):
    1. If the object of the XDI statement is NOT a cross-reference containing a complete XDI statement, then the value following the key MUST be a JSON array of JSON strings representing the XDI addresses of the target XDI objects.
    2. If the object of the XDI statement is a cross-reference containing a complete XDI statement, then the value of the array MUST be a nested JSON object representing an XDI inner graph that follows these rules recursively.

Examples

Non-Recursive

Following is an example graph in XDI single-line display format that includes explicit context statements:

//=abc
=abc//<#age>
=abc//<#photo>
=abc<#age>&/&/33
=abc<#age>//<$t>
=abc<#age>//[<$v>]
=abc<#age><$t>&/&/"2010-10-10T11:12:13Z"
=abc<#age>/$v/=abc<#age>[<$v>]@1
=abc<#age>[<$v>]//@0
=abc<#age>[<$v>]//@1
=abc<#age>[<$v>]@0&/&/32
=abc<#age>[<$v>]@0//<$t>
=abc<#age>[<$v>]@0<$t>&/&/"2010-09-09T10:11:12Z"
=abc<#age>[<$v>]@1/$ref/=abc<#age>
=abc<#photo>/$is#/$png$image$mime#
=abc<#photo>/$is#/$base64$binary#
=abc<#photo>&/&/"R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp"

Here is the same graph serialized in JSON (again including all explicit context statements).

{
    "/": [
        "=abc"
    ],
    "=abc/": [
        "<#age>",
        "<#photo>"
    ],
    "=abc<#age>/": [
        "<$t>",
        "[<$v>]"
    ],
    "=abc<#age>[<$v>]/": [
        "@0",
        "@1"
    ],
    "=abc<#age>[<$v>]@0/": [
        "<$t>"
    ],
    "=abc<#age>/$v": [
        "=abc<#age>[<$v>]@1"
    ],
    "=abc<#age>[<$v>]@1/$ref": [
        "=abc<#age>"
    ],
    "=abc<#photo>/$is#": [
        "$png$image$mime#",
        "$base64$binary#"
    ],
    "=abc<#age>&/&": 33,
    "=abc<#age><$t>&/&": "2010-10-10T11:12:13Z",
    "=abc<#age>[<$v>]@0&/&": 32,
    "=abc<#age>[<$v>]@0<$t>&/&": "2010-09-09T10:11:12Z",
    "=abc<#photo>&/&": "R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp"
}

Recursive

Following is an XDI message in XDI single-line display format that includes a $set operation whose object is an inner graph. Notes:

  1. This does not include any explicit context statements.
  2. The object of each $set statement is an XDI cross-reference describing the inner graph.

([+]!9999)/$set/[+]!9999[$msg]!1234
[+]!9999[$msg]!1234/$is()/([=]!3333)
[+]!9999[$msg]!1234<$t>&/&/"2011-04-10T22:22:22Z"
[+]!9999[$msg]!1234/$do/[=]!3333$do
[+]!9999[$msg]!1234$do/$set/([=]!3333[<#tel>]!1&/&/"+1.206.555.1111")
[+]!9999[$msg]!1234$do/$set/([=]!3333[<#tel>]!2&/&/"+1.206.555.2222")
[+]!9999[$msg]!1234$do/$set/([=]!3333[<#tel>]/#home/[=]!3333[<#tel>]!1)
[+]!9999[$msg]!1234$do/$set/([=]!3333[<#tel>]/#work/[=]!3333[<#tel>]!2)
[+]!9999[$msg]!1234$do/$set/([=]!3333[<#tel>]/#work#fax/[=]!3333[<#tel>]!2)
[+]!9999[$msg]!1234$do/$set/([=]!3333<#age>&/&/33)

Here is the same graph serialized in JSON (again exclusing all explicit context statements). The set of XDI cross-reference that are an object of the $set statement (an inner graph) are serialized as a nested JSON object.

{
    "([+]!9999)/$set": [
        "[+]!9999[$msg]!1234"
    ],
    "[+]!9999[$msg]!1234/$is()": [
        "([=]!3333)"
    ],
    "[+]!9999[$msg]!1234<$t>&/&": "2011-04-10T22:22:22Z",
    "[+]!9999[$msg]!1234/$do": [
        "[=]!3333$do"
    ],
    "[+]!9999[$msg]!1234$do/$set": [
        {
            "[=]!3333[<#tel>]!1&/&": "+1.206.555.1111",
            "[=]!3333[<#tel>]!2&/&": "+1.206.555.2222",
            "[=]!3333[<#tel>]/#home": [
                "[=]!3333[<#tel>]!1"
            ],
            "([=]!3333[<#tel>]/#work": [
                "[=]!3333[<#tel>]!2"
            ],
            "([=]!3333[<#tel>]/#work#fax": [
                "[=]!3333[<#tel>]!2"
            ],
            "([=]!3333<#age>&/&": 33
        }
    ]
}


CategoryProposal CategorySerialization CategoryHighPriority

XdiFlatSerialization (last edited 2014-04-04 17:08:16 by peacekeeper)