The JSON format

JSON, short for JavaScript Object Notation, is a generic text format easy for humans to read and write and it's easy for machines to parse it and generate it. This format is used by RavenDB to store data and databases' metadata. RavenDB can write the JSON document directly, simplifying the writing/updating process. It is important to know that the JSON format may "denormalize" data. We might be storing the same class object multiple times in the database but that is not a problem because we are storing the entire document and we retrieve it as a document and not as a piece of data.

The JSON format is built on two structures:

  • A collection of name/value pairs. Programming languages support this data structure in different names such as object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In various programming languages, this is realized as an array, vector, list, or sequence.

The following screenshot illustrates a Document entity as it will be stored in RavenDB using JSON format:

In this JSON example which describes the Computer entity, the object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma). So, the "CompuerID" entity represents the key name and "12345" represents the value assigned to that key name.

The "Inventory" key name is an array and is an ordered collection of values. In JSON, an array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma). In this example, the "Inventory" array contains two object instances where each one is composed of three name/value pairs "SoftawareName", "SoftwareVersion", and "InstallDate".

Tip

You can learn more about JSON structures at: http://www.json.org/.