The majority of requests and responses to CouchDB use the JavaScript Object Notation (JSON) for formatting the content and structure of the data and responses.
JSON is used because it is the simplest and easiest to use solution for working with data within a web browser, as JSON structures can be evaluated and used as JavaScript objects within the web browser environment. JSON also integrates with the server-side JavaScript used within CouchDB.
JSON supports the same basic types as supported by JavaScript, these are:
Number (either integer or floating-point).
String; this should be enclosed by double-quotes and supports Unicode characters and backslash escaping. For example:
"A String"
Boolean - a true
or
false
value. You can use these strings
directly. For example:
{ "value": true}
Array - a list of values enclosed in square brackets. For example:
["one", "two", "three"]
Object - a set of key/value pairs (i.e. an associative array, or hash). The key must be a string, but the value can be any of the supported JSON values. For example:
{ "servings" : 4, "subtitle" : "Easy to make in advance, and then cook when ready", "cooktime" : 60, "title" : "Chicken Coriander" }
In CouchDB, the JSON object is used to represent a variety of structures, including the main CouchDB document.
Parsing JSON into a JavaScript object is supported through the
eval()
function in JavaScript, or through
various libraries that will perform the parsing of the content
into a JavaScript object for you. Libraries for parsing and
generating JSON are available in many languages, including Perl,
Python, Ruby, Erlang and others.
Care should be taken to ensure that your JSON structures are valid, invalid structures will cause CouchDB to return an HTTP status code of 500 (server error). See HTTP Status Code 500 .