CJ2k | 2023-04-12 22:22:49 UTC | #1
Just cannot seem to get my translation/successTemplate to work. Trying to return "name" from a database table
{ "translationMap": { "name": "$..name" }, "translationMapDefaults": {}, "successTemplate": "{\"name\": ${successTemplateUtils.firstFromArray(${name})}}" }
data action test results in... Validate output against schema: JSON failed output schema validation for the following reasons: Schema: # @/properties/name. Error location: /name. instance type (object) does not match any allowed primitive type (allowed: ["string"])
using rawResult returns { "Count": 1, "Items": [ { "date": { "S": "12/1/2000" }, "name": { "S": "Jon Doe" }, "customerid": { "S": "12345" } } ], "ScannedCount": 1 }
Jerome.Saint-Marc | 2023-04-13 07:25:56 UTC | #2
Hello,
Please post/share what you have defined in your Output Contract. I think the problem is there.
Regards,
CJ2k | 2023-04-13 13:22:05 UTC | #3
*Data action contract is *
{ "title": "Dynamodata", "type": "object", "properties": { "date": { "type": "string" }, "name": { "type": "string" } }, "additionalProperties": true }
*The mapping template from the database table extract is * { "TableName": "Customers", "PrimaryKey": "customerid", "KeyConditionExpression": "customerid = :v1", "ExpressionAttributeValues": { ":v1": { "S": "$input.params('customerid')" } } }
Jerome.Saint-Marc | 2023-04-13 13:37:50 UTC | #4
The problem is in your translationMap. I had missed that - didn't pay enough attention to your sample rawResult.
Given the example you have posted, the JSONPath expression you have defined: "name": "$..name"* will return:
[ { "S": "Jon Doe" } ]
Then, taking first element in the array ({"S": "John Doe"}) and trying to assign it to a string variable fails.
Your JSONPath expression should be: "name": "$..name.S"
Regards,
CJ2k | 2023-04-13 17:26:53 UTC | #5
Jerome.Saint-Marc, post:4, topic:19421
our JSONPath expression should be: "name": "$..name.S"
Awesome! Works. Really appreciate it.
system | 2023-05-14 17:27:48 UTC | #6
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 19421