'How to remove JSON schema dynamically without hardcode in the output from API gateway response
I know this is similar to this one but I am trying to remove JSON schema dynamically without using their data-types/key-params hardcoded in the loop.
This is the response from Integration response having dynamodb schema JSON structure.
{
Items: [
{
{key1: {S: "Value1_1"}, key2:{S: "Value2_1"}, key3:{S: "Value3_1"}},
{key1: {S: "Value1_2"}, key2:{S: "Value2_2"}, key3:{S: "Value3_2"}},
{key1: {S: "Value1_3"}, key2:{S: "Value2_3"}, key3:{S: "Value3_3"}}
}
]
}
I need to get this response from the above
{
Items: [
{key1: "Value1_1", key2: "Value2_1",key3: "Value3_1"},
{key1: "Value1_2", key2: "Value2_2",key3: "Value3_2"},
{key1: "Value1_3", key2: "Value2_3",key3: "Value3_3"},
]
}
Here is my code which I am trying to get that valid JSON.
#set($inputRoot = $input.path('$'))
{
"Items": [
#foreach($elem in $inputRoot.Items)
#foreach($paramName in $elem.keySet())
#foreach($paramType in $paramName.keySet())
{
"$paramName" : "$util.escapeJavaScript($paramName.get($paramType))"
}
#if($foreach.hasNext),#end
#end
#if($foreach.hasNext),#end
#end
#if($foreach.hasNext),#end
#end
]
}
Can someone help me here to achieve the valid JSON format
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
