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
Key | Value |
---|---|
_id | A string representing the book’s unique International Standard Book Number (ISBN) |
title | A string representing the book’s title |
subtitle | A string representing the book’s subtitle |
authors | A JSON array of authors with each element being a string representing the author’s name |
publisher | A string representing the name of the publisher |
released | A string representing the date in ISO 8601 format |
pages | A 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.