JSON

CouchDB stores documents as JSON (JavaScript Object Notation) objects. JSON is a human-readable and lightweight data interchange format. Data structures from many programming languages can easily be converted to and from JSON. The following is an example (that will be used in Chapter 2) of a JSON object representing a book:

{
   "_id":"978-0-596-15589-6",
   "title":"CouchDB: The Definitive Guide",
   "subtitle":"Time to Relax",
   "authors":[
      "J. Chris Anderson",
      "Jan Lehnardt",
      "Noah Slater"
   ],
   "publisher":"O'Reilly Media",
   "released":"2010-01-19",
   "pages":272
}

A JSON object is a collection of key/value pairs. The book object above contains the keys and values listed in Table 1-1. JSON values can be strings, numbers, booleans (false or true), arrays (e.g., [ "J. Chris Anderson", "Jan Lehnardt", "Noah Slater" ]), null, or another JSON object.

Table 1-1. Key/value pairs in a JSON book object

KeyValue
_idA string representing the book’s unique International Standard Book Number (ISBN)
titleA string representing the book’s title
subtitleA string representing the book’s subtitle
authorsA JSON array of authors with each element being a string representing the author’s name
publisherA string representing the name of the publisher
releasedA string representing the date in ISO 8601 format
pagesA number representing the number of pages contained within the book

Get Writing and Querying MapReduce Views in CouchDB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.