Skip to content

JSON Representation

krestenkrab edited this page Mar 2, 2011 · 3 revisions

The following describes the JSON representation format for vector maps.

A simple map with keys "A" and "B" is represented very straight-forwardly as a JSON object with the same two keys, plus an additional "_meta" structure describing all the internals necessary to maintain causal relations.

{
  "_meta": { ... },
  "A" : "1",
  "B" : "2"
}

The _meta object contains enough information, so as to allow a third party to mutate the "other" keys (in this case A, and B), introduce new keys, or delete entries; and reconstruct a valid vector map JSON representation. Here is an example of a full vector map:

{
  "_meta": {
     "A" : { 
          hash    : "FD24BE2B93C7C7BF3E012699F875F4377CB33BBA",
          vclock  : { peter:[2,23423424], jens:[1,23423423]} 
     },
     "B" : { 
          hash    : "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3",
          vclock  : {jens:[1,23423423], krab:[1,23423412]},
          alts    : ["3"] 
     },
     "C" : { 
          deleted : true, 
          vclock  : {peter:[2,23423424]} 
     },
  },
  "A" : "1",
  "B" : "2",
}

For all keys, the _meta.Key entry contains the relevant vector version for the relevant entry. So, you can see that A was been edited by both jens and most recently peter.

The key B is in conflict. The most recent edit "B" : "2" (by Jens) is stored in the value of the top-level object; and the alternative(s) is stored in _meta.B.alts.

The key C has been deleted from the map, so only the meta data contains information for it.

Content Values

In vetcor map JSON representation, values are either

  • strings (original value is text/plain content type)
  • vector maps (which are translated recursively as in this specification)
  • mime encoded values

Mime encoded values are represented as a JSON object with attributes content_type (a string), and body, the Base64 encoded content representation.

{
  content_type: "application/binary"
  body: "YmluYXJ5IGVuY29kZWQgc3RyaW5n"
}
Clone this wiki locally