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:
This outputs:
I've tried to use
also trying to print just one value leads to the same which makes me think I need to try a different approach
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.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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' ]) |
1 2 |
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' }] |
1 2 |
data = json.loads(response) data[ "x1" ] = x1 |
1 |
print (data [ 'device_data' ][ 0 ][ 'x1' ]) |
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.