JSON Document Data Types
HPE Ezmeral Data Fabric 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 as follows:
{ "_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 that represents the number of DAYS since epoch, that is. 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 that represents time of the day in milliseconds. The value is absolute and is time-zone independent. |
Timestamp | A 64-bit integer that represents the number of milliseconds since epoch, that is, 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 as follows:
{ "_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!" } ] }
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. However, you should consider the extra complexity that additional nestings may add to your applications.
Arrays
features
: An array with two scalar stringscomments
: 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!" } ] }