I am trying to read data from dynamoDB and let Alexa speak it. I am successfully retrieving the data, it's just that I'm having trouble with the JSON part (I'm new to it and I can't find the answer online).
Here's the function I am using to get the data (from https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html):
var x = DBClient.get(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:",
JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
} });
And here is how I'm logging the variable: console.log("You can expect " + x);
In the function logs, I'm basically getting [object Object] for x.
I tried doing x.Item.Answer but that didn't work (Answer is the attribute name for the data that I'm trying to fetch)
I tried to use JSON.parse on x, but I got errors
I also tried JSON.stringify, which returned as an error "Converting circular structure to JSON" since I guess the function "get" (which i cannot find any documentation on) returns an already stringified version?
I don't know what to try anymore ...
As a note, here's the JSON that I'm (successfully) returning from the database:
{
"Item": {
"Answer": "Sunny weather",
"Question": "What is the weather like today"
}
}