DynamoDB JSON Conversion Utility

1.2.0 · maintenance · verified Thu Apr 16

dynamo-json is a Python utility library (currently v1.2.0) designed to facilitate seamless conversion between standard Python objects (including Decimal, datetime, and UUID) and the specialized JSON format used by Amazon DynamoDB. It provides `dumps` and `loads` functions that mimic the standard `json` library, handling the DynamoDB type descriptors (e.g., {'S': 'string'}, {'N': '123'}) automatically. The library has been in maintenance mode since its last update in 2020, with a focus on stable functionality.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates converting a complex Python dictionary containing Decimals, datetimes, and UUIDs to DynamoDB-compatible JSON and back. The `json_util` module handles the necessary type marshalling and unmarshalling.

import time
import uuid
from datetime import datetime
from decimal import Decimal
from dynamo_json import json_util as json

# Python object with various types, including those requiring special handling by DynamoDB
json_ = {
    "MyString": "a",
    "num": 4,
    "MyBool": False,
    "my_dict": {"my_date": datetime.now(), "my_uuid": uuid.uuid4()},
    "MyList": [Decimal('1.23'), 2, 3],
    "MyNull": None
}

# Convert Python object to DynamoDB JSON format
dynamo_json_data = json.dumps(json_)
print("DynamoDB JSON:\n", dynamo_json_data)

# Convert DynamoDB JSON format back to a Python object
python_object = json.loads(dynamo_json_data)
print("Python object:\n", python_object)

view raw JSON →