CJ2k
April 12, 2023, 10:22pm
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
}
Hello,
Please post/share what you have defined in your Output Contract.
I think the problem is there.
Regards,
CJ2k
April 13, 2023, 1:22pm
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')"
}
}
}
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
April 13, 2023, 5:26pm
5
Awesome! Works. Really appreciate it.
system
Closed
May 14, 2023, 5:27pm
6
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.