Amazon DynamoDB
Developer Guide (API Version 2012-08-10)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

JSON Data Format

Amazon DynamoDB uses JavaScript Object Notation format (JSON) to send and receive formatted data. JSON presents data in a hierarchy so that both data values and data structure are conveyed simultaneously. Name-value pairs are defined in the format name:value. The data hierarchy is defined by nested brackets of name-value pairs.

For example, the following shows a table named "users" with a composite primary key based on the attributes user and time.

{
    "Table": {
        "AttributeDefinitions": [
            {
                "AttributeName": "user",
                "AttributeType": "S"
            },
            {
                "AttributeName": "time",
                "AttributeType": "N"
            }
        ],
        "TableName": "users",
        "KeySchema": [
            {
                "AttributeName": "user",
                "KeyType": "HASH"
            },
            {
                "AttributeName": "time",
                "KeyType": "RANGE"
            }
        ],
        "TableStatus": "ACTIVE",
        "CreationDateTime": Mon Mar 25 09:46:00 PDT 2013,
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0,
            "ReadCapacityUnits": 10,
            "WriteCapacityUnits": 10
        },
        "TableSizeBytes": 949,
        "ItemCount": 23
    }
}
			

In this and other JSON notation, the following abbreviations are used to denote data types:

  • S—String

  • N—Number

  • B—Binary

  • SS—String set

  • NS—Number set

  • BS—Binary set

For more information about data types, see Amazon DynamoDB Data Types.

JSON Is for the Transport Protocol Only

Amazon DynamoDB uses JSON only as a transport protocol. You use JSON notation to send data, and Amazon DynamoDB responds with JSON notation, but the data is not being stored "on-disk" in the JSON data format.

Applications that use Amazon DynamoDB must either implement their own JSON parsing or use a library like one of the AWS SDKs to do this parsing for them.

Many libraries support the JSON Number type by using the data types int, long and double. . However, because Amazon DynamoDB provides a Numeric type that does not map exactly to these other data types, these type distinctions can cause conflicts.

Unfortunately, many JSON libraries do not handle fixed-precision numeric values, and they automatically infer a double data type for digit sequences that contain a decimal point.

To solve these problems, Amazon DynamoDB provides a single numeric type with no data loss. To avoid unwanted implicit conversions to a double value, it uses strings for the data transfer of numeric values. This approach provides flexibility for updating attribute values while maintaining proper sorting semantics, such as putting the values "01", "2", and "03" in the proper sequence.

Transferring Binary Data Type Values in JSON

Amazon DynamoDB supports binary attributes. However, JSON does not natively support encoding binary data. To send binary data over the wire, you will need to encode it as Base64 text. Upon receiving the payload Amazon DynamoDB decodes the payload back to binary.

For more information about the Base64 encoding, go to http://tools.ietf.org/html/rfc4648. However, note the following Amazon DynamoDB specific restrictions:

  • The Base64 encoding may not include characters that are outside of the Base64 character set, whitespaces, or line separators.

  • The encoded data must include the correct number of padding characters as required by the Base64 encoding guidelines.

  • The DynamoDB Base64 encoding uses the characters '/' and '+', as illustrated in table 1 in the preceding RFC.