• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Alonreznik/dynamodb-json: DynamoDB JSON util to load and dump strings of Dynamod ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

Alonreznik/dynamodb-json

开源软件地址:

https://github.com/Alonreznik/dynamodb-json

开源编程语言:

Python 100.0%

开源软件介绍:

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:

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
# }



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap