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