CouchDB Data Types (JSON Format and Structure)

Data types are a fundamental concept in computer science, determining how variables or values are stored and processed. In NoSQL scalable data stores like CouchDB, data types are also very important.

JSON Basics

JSON (JavaScript Object Notation) is a lightweight, human-readable, and easy-to-program data interchange format. It is a key-value data structure where each value can be a string, number, boolean, array, or another JSON object.

JSON Object Structure

{
  "key1": "value1",
  "key2": 123,
  "key3": true,
  "key4": [1, 2, 3],
  "key5": {
    "subkey1": "subvalue1",
    "subkey2": 456
  }
}

JSON Data Types

In CouchDB, JSON is a standard data type and can be used as the value of a document.

JSON Data Types

  • string: A string value.
  • integer: An integer value.
  • double: A floating-point value (can be precise to several decimal places).
  • boolean: A boolean value (can be true or false).
  • array: An array or expression value (containing multiple values).
  • object: A JSON object (containing key-value pairs).

Supported JSON Values

CouchDB supports the following JSON values:

  • null
  • undefined
{
  "name": "John Doe",
  "age": null,
  " occupation": undefined,
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Properties

In CouchDB, JSON objects can have multiple properties. The value of each property must be a supported data type.

JSON Object Property Example

{
  "key1": "value1",
  "key2": {
    "subkey1": "subvalue1",
    "subkey2": [1, 2, 3]
  },
  "key3": true,
  "key4": [
    { "name": "John Doe", "age": 30 },
    { "name": "Jane Smith", "age": 25 }
  ]
}

JSON Object Property Constraints

In CouchDB, every property of a JSON object is optional (i.e., it may not exist). If a document does not specify a property, it is considered absent.

JSON Object Property Duplication

CouchDB supports duplicate JSON object properties. These properties can appear in multiple documents, and CouchDB will automatically handle them.

{
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" },
    { "value": 25, "unit": "months" }
  ]
}

JSON Object Property Sorting

CouchDB supports sorting JSON object properties. These properties can be arranged in a specific order within a document.

{
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 25, "unit": "months" },
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Copying

CouchDB supports copying JSON object properties. These properties can appear in multiple documents, and CouchDB will automatically handle them.

{
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" },
    { "value": 25, "unit": "months" }
  ]
}

JSON Object Property Indexing

CouchDB supports indexing JSON object properties. This allows you to more easily find documents and filter based on specific property values.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" },
    { "value": 25, "unit": "months" }
  ]
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to more easily change the value of a specific property in a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" },
    { "value": 25, "unit": "months" }
  ]
}

JSON Object Property Deletion

CouchDB supports deleting JSON object properties. This allows you to more easily remove a specific property from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Merge

CouchDB supports merging JSON object properties. This allows you to more easily merge two or more documents into a single document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Split

CouchDB supports splitting JSON object properties. This allows you to more easily split a document into multiple separate documents.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Duplicate Removal

CouchDB supports removing duplicate JSON object properties. This allows you to more easily remove duplicate property values from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to more easily change the value of a specific property in a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "456 Elm St",
    "city": "Othertown",
    "state": "NY",
    "zip": "67890"
  }
}

JSON Object Property Deletion

CouchDB supports deleting JSON object properties. This allows you to more easily remove a specific property from a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Merge

CouchDB supports merging JSON object properties. This allows you to more easily merge two or more documents into a single document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Split

CouchDB supports splitting JSON object properties. This allows you to more easily split a document into multiple separate documents.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Duplicate Removal

CouchDB supports removing duplicate JSON object properties. This allows you to more easily remove duplicate property values from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to more easily change the value of a specific property in a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "456 Elm St",
    "city": "Othertown",
    "state": "NY",
    "zip": "67890"
  }
}

JSON Object Property Deletion

CouchDB supports deleting JSON object properties. This allows you to more easily remove a specific property from a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Merge

CouchDB supports merging JSON object properties. This allows you to more easily merge two or more documents into a single document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Split

CouchDB supports splitting JSON object properties. This allows you to more easily split a document into multiple separate documents.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Duplicate Removal

CouchDB supports removing duplicate JSON object properties. This allows you to more easily remove duplicate property values from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to more easily change the value of a specific property in a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "456 Elm St",
    "city": "Othertown",
    "state": "NY",
    "zip": "67890"
  }
}

JSON Object Property Deletion

CouchDB supports deleting JSON object properties. This allows you to more easily remove a specific property from a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Merge

CouchDB supports merging JSON object properties. This allows you to more easily merge two or more documents into a single document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Split

CouchDB supports splitting JSON object properties. This allows you to more easily split a document into multiple separate documents.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Duplicate Removal

CouchDB supports removing duplicate JSON object properties. This allows you to more easily remove duplicate property values from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to more easily change the value of a specific property in a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "456 Elm St",
    "city": "Othertown",
    "state": "NY",
    "zip": "67890"
  }
}

JSON Object Property Deletion

CouchDB supports deleting JSON object properties. This allows you to more easily remove a specific property from a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Merge

CouchDB supports merging JSON object properties. This allows you to more easily merge two or more documents into a single document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Split

CouchDB supports splitting JSON object properties. This allows you to more easily split a document into multiple separate documents.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Duplicate Removal

CouchDB supports removing duplicate JSON object properties. This allows you to more easily remove duplicate property values from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to more easily change the value of a specific property in a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "456 Elm St",
    "city": "Othertown",
    "state": "NY",
    "zip": "67890"
  }
}

JSON Object Property Deletion

CouchDB supports deleting JSON object properties. This allows you to more easily remove a specific property from a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Merge

CouchDB supports merging JSON object properties. This allows you to more easily merge two or more documents into a single document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Split

CouchDB supports splitting JSON object properties. This allows you to more easily split a document into multiple separate documents.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Duplicate Removal

CouchDB supports removing duplicate JSON object properties. This allows you to more easily remove duplicate property values from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to more easily change the value of a specific property in a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "456 Elm St",
    "city": "Othertown",
    "state": "NY",
    "zip": "67890"
  }
}

JSON Object Property Deletion

CouchDB supports deleting JSON object properties. This allows you to more easily remove a specific property from a document.

{
  "_id": "doc1",
  "name": {
    "first": "Jane",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ]
}

JSON Object Property Merge

CouchDB supports merging JSON object properties. This allows you to more easily merge two or more documents into a single document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Split

CouchDB supports splitting JSON object properties. This allows you to more easily split a document into multiple separate documents.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Duplicate Removal

CouchDB supports removing duplicate JSON object properties. This allows you to more easily remove duplicate property values from a document.

{
  "_id": "doc1",
  "name": {
    "first": "John",
    "last": "Doe"
  },
  "age": [
    { "value": 30, "unit": "years" }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  }
}

JSON Object Property Update

CouchDB supports updating JSON object properties. This allows you to