0

I have a API gateway which does a get to the tables stored in dynamo DB. The table stored looks like as JSON as show below

{
  "photos": {
    "page": 1,
    "pages": "1234",
    "perpage": 100,
    "photo": [
      {
        "farm": 1,
        "id": "12345678901",
        "isfamily": 0,
        "isfriend": 0,
        "ispublic": 1,
        "owner": "23456789@A12",
        "secret": "abc123d456",
        "server": "1234",
        "title": "Sample photo 1"
      },
      {
        "farm": 2,
        "id": "23456789012",
        "isfamily": 0,
        "isfriend": 0,
        "ispublic": 1,
        "owner": "34567890@B23",
        "secret": "bcd234e567",
        "server": "2345",
        "title": "Sample photo 2"
      }
    ],
    "total": "123398"
  },
  "srini": "srini"
}

With out integration response mapping template I get the table as shown below

  {  
 "Count": 1,   "Items": [
            {
              "photos": {
                "M": {
                  "photo": {
                    "L": [
                      {
                        "M": {
                          "owner": {
                            "S": "23456789@A12"
                          },
                          "server": {
                            "S": "1234"
                          },
                          "ispublic": {
                            "N": "1"
                          },
                          "isfriend": {
                            "N": "0"
                          },
                          "farm": {
                            "N": "1"
                          },
                          "id": {
                            "S": "12345678901"
                          },
                          "secret": {
                            "S": "abc123d456"
                          },
                          "title": {
                            "S": "Sample photo 1"
                          },
                          "isfamily": {
                            "N": "0"
                          }
                        }
                      },
                      {
                        "M": {
                          "owner": {
                            "S": "34567890@B23"
                          },
                          "server": {
                            "S": "2345"
                          },
                          "ispublic": {
                            "N": "1"
                          },
                          "isfriend": {
                            "N": "0"
                          },
                          "farm": {
                            "N": "2"
                          },
                          "id": {
                            "S": "23456789012"
                          },
                          "secret": {
                            "S": "bcd234e567"
                          },
                          "title": {
                            "S": "Sample photo 2"
                          },
                          "isfamily": {
                            "N": "0"
                          }
                        }
                      }
                    ]
                  },
                  "perpage": {
                    "N": "100"
                  },
                  "total": {
                    "S": "123398"
                  },
                  "pages": {
                    "S": "1234"
                  },
                  "page": {
                    "N": "1"
                  }
                }
              },
              "srini": {
                "S": "srini"
              }
            }   ],   "ScannedCount": 1 
}

I am trying to retrieve in the JSON format so that web client takes the table from Dynamo in JSON format .The mapping template I am trying to write is as follows

#set($inputRoot = $input.path('$'))
{
        #foreach($elem in $inputRoot.Items) {
                "srini": "$elem.srini.S",
                "pages": "$elem.photos.pages.S",

                 #foreach($elemnext in $elem.photos.photo) {
                     "id": "$elemnext.id.S"

                }#if($foreach.hasNext),#end
               #end

            }#if($foreach.hasNext),#end
        #end

}

I only can retrieve srini as show below

Response Body
{
         {
                "srini": "srini",
                "pages": ""
                             }            
}

All other data is not retreived ,What is the right way to write mapping template ,Can any one let me know please?

1 Answer 1

6
#set($inputRoot = $input.path('$'))
{
        #foreach($elem in $inputRoot.Items) {
                "srini": "$elem.srini.S",
                "pages": "$elem.photos.M.pages.S",
                 #foreach($elemnext in $elem.photos.M.photo.L)
                 {
                    "id": "$elemnext.M.id.S"
                 } #if($foreach.hasNext),#end
                #end

            }#if($foreach.hasNext),#end
        #end

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.