# 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
# }
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Alonreznik/dynamodb-json",
"name": "dynamodb-json",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python dynamodb amazon json aws",
"author": "Alon Reznik",
"author_email": "alonreznik@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6f/65/7216f2111c4e47ffb44b6415334c221d5543ce2a85c8d80e155e7cb06851/dynamodb_json-1.4.2.tar.gz",
"platform": null,
"description": "# DynamoDB Json\nDynamoDB json util to load and dump strings of Dynamodb json format to python object and vise-versa\n\n# Install\njust use pip: \n```\npip install dynamodb-json\n```\n\n# Use\n\nThe dynamodb-json util works the same as json loads and dumps functions:\n\n```python\nimport time\nimport uuid\nfrom datetime import datetime\nfrom decimal import Decimal\n\nfrom dynamodb_json import json_util as json\n\njson_ = {\"MyString\": \"a\",\n \"num\": 4,\n \"MyBool\": False,\n \"my_dict\": {\"my_date\": datetime.utcnow()},\n \"MyNone\": None,\n \"MyZero\": 0,\n \"myDecimal\": Decimal(\"19.2\"), # converts Decimal to float, load it as float\n \"myLong\": long(1938475658493),\n \"MyNestedDict\": {\n \"my_other_nested\": {\n \"name\": \"John\",\n \"surname\": \"Lennon\",\n \"MyOtherNone\": None,\n \"floaty\": float(29.4),\n \"myList\": [1, 3, 4, 5, 6, \"This Is Sparta!\"],\n \"mySet\": {1, 3, 4, 5, 6}, # converts set to list, returns as list\n \"myUUID\": uuid.uuid4(), # converts uuid to string, loads it as string\n \"time\": time.time() # converts it to seconds python float, loads it as float\n }\n }\n }\n\ndynamodb_json = json.dumps(json_)\n\n# {\n# \"my_dict\": {\"M\": {\"my_date\": {\"S\": \"2017-04-22T14:41:35.780000\"}}}, \n# \"MyBool\": {\"BOOL\": false}, \"MyNone\": {\"NULL\": true}, \n# \"MyNestedDict\": {\n# \"M\": {\"my_other_nested\": {\n# \"M\": {\"myUUID\": {\"S\": \"2f4ad21e098f49b18e22ad209779048b\"}, \n# \"surname\": {\"S\": \"Lennon\"}, \"name\": {\"S\": \"John\"}, \n# \"mySet\": {\"L\": [{\"N\": \"1\"}, {\"N\": \"3\"}, {\"N\": \"4\"}, {\"N\": \"5\"}, {\"N\": \"6\"}]}, \n# \"floaty\": {\"N\": \"29.4\"}, \"time\": {\"N\": \"1492872095.78\"}, \n# \"myList\": {\"L\": [{\"N\": \"1\"}, {\"N\": \"3\"}, {\"N\": \"4\"}, {\"N\": \"5\"}, {\"N\": \"6\"}, {\"S\": \"This Is Sparta!\"}]}, \n# \"MyOtherNone\": {\"NULL\": true}}\n# }\n# }\n# }, \n# \"myDecimal\": {\"N\": \"19.2\"}, \"num\": {\"N\": \"4\"}, \n# \"MyString\": {\"S\": \"a\"}, \n# \"myLong\": {\"N\": \"1938475658493\"}, \n# \"MyZero\": {\"N\": \"0\"}\n# }\n\n\njson.loads(dynamodb_json)\n\n# {'my_dict': {'my_date': datetime.datetime(2017, 4, 22, 14, 41, 35, 780000)}, 'MyBool': False, 'MyNone': None,\n# 'MyNestedDict': {\n# 'my_other_nested': {'myUUID': '2f4ad21e098f49b18e22ad209779048b', \n# 'surname': 'Lennon', 'name': 'John',\n# 'mySet': [1, 3, 4, 5, 6], \n# 'floaty': 29.4, \n# 'time': 1492872095.78,\n# 'myList': [1, 3, 4, 5, 6, 'This Is Sparta!'], \n# 'MyOtherNone': None\n# }\n# }, \n# 'myDecimal': 19.2,\n# 'num': 4, \n# 'MyString': 'a', \n# 'myLong': 1938475658493L, \n# 'MyZero': 0\n# }\n```\n",
"bugtrack_url": null,
"license": "Mozilla",
"summary": "A DynamoDB json util from and to python objects",
"version": "1.4.2",
"project_urls": {
"Homepage": "https://github.com/Alonreznik/dynamodb-json"
},
"split_keywords": [
"python",
"dynamodb",
"amazon",
"json",
"aws"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d2061b30b1e89ff8e86215e8e0fb1cbf3004976f5435b9dcafc3c1f7623e2a77",
"md5": "f229c92328677c76182f1406bd8a8361",
"sha256": "b78259bb13cf96695ab6554d6616341ace4e2530e24cedb738a01a7cef828309"
},
"downloads": -1,
"filename": "dynamodb_json-1.4.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "f229c92328677c76182f1406bd8a8361",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 9470,
"upload_time": "2024-05-18T17:58:13",
"upload_time_iso_8601": "2024-05-18T17:58:13.209742Z",
"url": "https://files.pythonhosted.org/packages/d2/06/1b30b1e89ff8e86215e8e0fb1cbf3004976f5435b9dcafc3c1f7623e2a77/dynamodb_json-1.4.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6f657216f2111c4e47ffb44b6415334c221d5543ce2a85c8d80e155e7cb06851",
"md5": "6b57cd54b8abcad3b14b8b23ec3bd3bf",
"sha256": "a304b4117877f3697af5554158e5034c3c48973a3ba49ecf49dddb09ac502b03"
},
"downloads": -1,
"filename": "dynamodb_json-1.4.2.tar.gz",
"has_sig": false,
"md5_digest": "6b57cd54b8abcad3b14b8b23ec3bd3bf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9288,
"upload_time": "2024-05-18T17:58:14",
"upload_time_iso_8601": "2024-05-18T17:58:14.757768Z",
"url": "https://files.pythonhosted.org/packages/6f/65/7216f2111c4e47ffb44b6415334c221d5543ce2a85c8d80e155e7cb06851/dynamodb_json-1.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-18 17:58:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Alonreznik",
"github_project": "dynamodb-json",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "dynamodb-json"
}