Hi,
I need to take some JSON values that are floats from an AWS DynamoDB and make them variables to use in my script but I keep on running into problems.
The code that works to retrieve them is:
Please can you help point me to resources that are useful for explaining how to parse the output so I can use them in my downstream code.
I need to take some JSON values that are floats from an AWS DynamoDB and make them variables to use in my script but I keep on running into problems.
The code that works to retrieve them is:
import boto3, json
from boto3.dynamodb.conditions import Key, Attr
# Declare the empty variables ready
x1 = 0.0
y1 = 0.0
x2 = 0.0
y2 = 0.0
x3 = 0.0
y3 = 0.0
TABLE_NAME = "xx_data"
# Dynamo connection
dynamodb_client = boto3.client('dynamodb', region_name="xxx")
dynamodb = boto3.resource('dynamodb', region_name="xxx")
table = dynamodb.Table(TABLE_NAME)
response = table.query(
KeyConditionExpression=Key('xx').eq('xx')
)
print(response['Items'])This outputs:xxx@xxxx ~ % /usr/bin/python3 /Volumes/xxxx/PyFiles/DynamoData.py
[{'device_data': {'y1': '1.663024479783291', 'x1': '0.6768443826584553', 'y2': '1.9438666581951096', 'x2': '1.39031925550876', 'y3': '2.179626982558035', 'x3': '2.0613910485295945'}, 'xx': 'xx'}]I've tried to use data = json.loads(response) data["x1"] = x1also trying to print just one value leads to the same which makes me think I need to try a different approach
print(data ['device_data'][0]['x1'])But both give me errors about how JSON needs to be a string.
Please can you help point me to resources that are useful for explaining how to parse the output so I can use them in my downstream code.
