Skip to main content

A DynamoDB json util from and to python objects

Project description

# DynamoDB Json
DynamoDB json util to load and dump strings of Dynamodb json format to python object and vise-versa

# Install
just use pip:
```
pip install dynamodb-json
```
# Use

The dynamodb-json util works the same as json loads and dumps functions:
```python
import time
import uuid
from datetime import datetime
from decimal import Decimal

from dynamodb_json import json_util as json

json_ = {"MyString": "a",
"num": 4,
"MyBool": False,
"my_dict": {"my_date": datetime.utcnow()},
"MyNone": None,
"MyZero": 0,
"myDecimal": Decimal("19.2"), # converts Decimal to float, load it as float
"myLong": long(1938475658493),
"MyNestedDict": {
"my_other_nested": {
"name": "John",
"surname": "Lennon",
"MyOtherNone": None,
"floaty": float(29.4),
"myList": [1, 3, 4, 5, 6, "This Is Sparta!"],
"mySet": {1, 3, 4, 5, 6}, # converts set to list, returns as list
"myUUID": uuid.uuid4(), # converts uuid to string, loads it as string
"time": time.time() # converts it to seconds python float, loads it as float
}
}
}

dynamodb_json = json.dumps(json_)

# {
# "my_dict": {"M": {"my_date": {"S": "2017-04-22T14:41:35.780000"}}},
# "MyBool": {"BOOL": false}, "MyNone": {"NULL": true},
# "MyNestedDict": {
# "M": {"my_other_nested": {
# "M": {"myUUID": {"S": "2f4ad21e098f49b18e22ad209779048b"},
# "surname": {"S": "Lennon"}, "name": {"S": "John"},
# "mySet": {"L": [{"N": "1"}, {"N": "3"}, {"N": "4"}, {"N": "5"}, {"N": "6"}]},
# "floaty": {"N": "29.4"}, "time": {"N": "1492872095.78"},
# "myList": {"L": [{"N": "1"}, {"N": "3"}, {"N": "4"}, {"N": "5"}, {"N": "6"}, {"S": "This Is Sparta!"}]},
# "MyOtherNone": {"NULL": true}}
# }
# }
# },
# "myDecimal": {"N": "19.2"}, "num": {"N": "4"},
# "MyString": {"S": "a"},
# "myLong": {"N": "1938475658493"},
# "MyZero": {"N": "0"}
# }


json.loads(dynamodb_json)

# {'my_dict': {'my_date': datetime.datetime(2017, 4, 22, 14, 41, 35, 780000)}, 'MyBool': False, 'MyNone': None,
# 'MyNestedDict': {
# 'my_other_nested': {'myUUID': '2f4ad21e098f49b18e22ad209779048b',
# 'surname': 'Lennon', 'name': 'John',
# 'mySet': [1, 3, 4, 5, 6],
# 'floaty': 29.4,
# 'time': 1492872095.78,
# 'myList': [1, 3, 4, 5, 6, 'This Is Sparta!'],
# 'MyOtherNone': None
# }
# },
# 'myDecimal': 19.2,
# 'num': 4,
# 'MyString': 'a',
# 'myLong': 1938475658493L,
# 'MyZero': 0
# }
```


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamodb-json-1.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamodb_json-1.2-py2.py3-none-any.whl (7.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dynamodb-json-1.2.tar.gz.

File metadata

  • Download URL: dynamodb-json-1.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dynamodb-json-1.2.tar.gz
Algorithm Hash digest
SHA256 913b8951dcecffab601a3db3ea36d987c713af2dd7be4a7878b4a1be725f3c35
MD5 d1a2007911fd5a18e4adc4799ce5baca
BLAKE2b-256 5931348a30ab2fcc878605eccb7ba1e9d3157ce37568e9cf304285729032dbbf

See more details on using hashes here.

File details

Details for the file dynamodb_json-1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for dynamodb_json-1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1b47b1272ea66cbc5c933c72e0ef1d93f6a2352c1d9ca72b08522e8465ed4efb
MD5 467c1f3a172a47fa7bcde50d1a0691c4
BLAKE2b-256 499860853a0bc8ffae28cb5af4a8ecfd5a95f0a46259cf2b96d3d40ede8c5472

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page