Home | Index

Address Book XML/JSON API Developer Guide

JSON Format

The JSON format represents data as JavaScript literals. The object literal produced by JSON can be directly evaluated by a JSON parser (such as json_decode in PHP or the json.org JSON library).

The following rules define the mapping from entities to JSON primitives (arrays, objects and properties):

It can be known statically if a particular property needs to be accessed as an object, or as an array of objects, which removes type-checking complexity on the receiving side. Although most data is stored in single-element arrays, this representation suggests fields are potentially multi-value. The plurality of a property is the same as the name of the composition relationship between the two entities. If the schema allows multiple children, the name of the property is plural. If the schema allows a single child, the name is singular.

[Note] Note

Although the examples throughout this specification show JSON structures indented for readability, the actual output from the Address Book JSON API is not indented.

Example

The search Response containing a single contact with name and phone fields (shown in the XML example above), looks like the following in JSON format:

{ "type": "search_response",
  "contacts": [
    { "type": "contact",
      "cid": 28,
      "fields": [
        { "type": "name",
          "fid": 30,
          "first": "Mike",
          "last": "Smith"
        },
        { "type": "phone",
           "fid": 33,
          "data": "408-349-1111",
          "work": true
        }
      ]
    }
  ]
}