JSON Document Data Types

MapR Database JSON documents support a richer set of data types beyond what JSON supports. JSON documents can have scalar data, nested documents, and arrays.

Scalar Data

Scalar data fields can contain strings or numbers. The scalar fields in the sample document are highlighted in bold below:

{
    "_id" : "2DT3201",
    "product_ID" : "2DT3201",
    "name" : " Allegro SPD-SL 6800",
    "brand" : "Careen",
    "category" : "Pedals",
    "type" : "Components",
    "price" : 112.99,
    "features" : [
        "Low-profile design",
        "Floating SH11 cleats included"
    ],
    "specifications" : {
        "weight_per_pair" : "260g",
        "color" : "black"
    },
    "comments" : [
        {
            "username" : "hlmencken",
            "comment" : "Best money I ever spent!"
        },
        {
            "username" : "vwoolf",
            "comment" : "What hlmencken said!"
        }
    ]
}

Scalar fields can contain the following data types:

Data Type Description
Binary An uninterpreted sequence of bytes
Boolean A data type of two possible values that are typically denoted by true and false
Byte A 8-bit signed integer that ranges in value from -128 to 127
Date A 32-bit integer representing the number of DAYS since epoch, i.e. January 1, 1970 00:00:00 UTC. The value is absolute and is time-zone independent.
Double A double-precision 64-bit floating-point number
Float A single-precision 32-bit floating-point number
Int A 32-bit signed integer that ranges in value from −2,147,483,648 to 2,147,483,647
Long A 64-bit signed integer that ranges in value from -(263) to 263 - 1
Short A 16-bit signed integer that ranges in value from −32,768 to 32,767
String A sequence of characters
Time A 32-bit integer representing time of the day in milliseconds. The value is absolute and is time-zone independent.
Timestamp A 64-bit integer representing the number of milliseconds since epoch, i.e. January 1, 1970 00:00:00 UTC. Negative values represent dates before epoch.

Nested Documents

Nested document fields can contain documents that themselves contain scalar data, nested documents, arrays, or a combination of any of these types. The nested documents in the sample document are highlighted in bold below:

{
    "_id" : "2DT3201",
    "product_ID" : "2DT3201",
    "name" : " Allegro SPD-SL 6800",
    "brand" : "Careen",
    "category" : "Pedals",
    "type" : "Components",
    "price" : 112.99,
    "features" : [
        "Low-profile design",
        "Floating SH11 cleats included"
    ],
    "specifications" : {
        "weight_per_pair" : "260g",
        "color" : "black"
    },
    "comments" : [
        {
            "username" : "hlmencken",
            "comment" : "Best money I ever spent!"
        },
        {
            "username" : "vwoolf",
            "comment" : "What hlmencken said!"
        }
    ]
}
Note: Nested documents can also be referred to as maps.

A nested document can include subfields that are themselves nested documents. In the following example, location is a nested document that has two nested document subfields, address and geoCoordinates:

{
   "_id": "001",
   "location": {
      "address": {
         "number": 100,
         "street": "Main St.",
         "city": "San Francisco",
         "state": "CA",
         "zipCode": "90210"
      },
      "geoCoordinates": {
         "latitude": 37.7817529521,
         "longitude": -122.39612197
      }
   }
}

There is no limit on the number of nestings in a nested document. You should consider the extra complexity additional nestings may add to your applications.

Arrays

Array fields contain lists of values that are accessible by means of index numbers. The values can be scalar, nested documents, arrays, or a combination of any of these types. For example, the following document has two arrays, both highlighted in bold:
  • features: An array with two scalar strings
  • comments: An array with two nested documents
{
    "_id" : "2DT3201",
    "product_ID" : "2DT3201", 
    "name" : " Allegro SPD-SL 6800",
    "brand" : "Careen",
    "category" : "Pedals",
    "type" : "Components",
    "price" : 112.99,
    "features" : [
        "Low-profile design",
        "Floating SH11 cleats included"
    ],
    "specifications" : {
        "weight_per_pair" : "260g",
        "color" : "black"
    },
    "comments" : [
        {
            "username" : "hlmencken",
            "comment" : "Best money I ever spent!"
        },
        {
            "username" : "vwoolf",
            "comment" : "What hlmencken said!"
        }
    ]
}
Note: Arrays can also be referred to as lists.