3

(Here's my Model scheme:

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "QuestionsModel",
"type": "array",
"items": {
"type": "object",
"properties": {
    "section_name": { "type": "string" },
    "options" : { 
        "type" : "array",
        "items" : {
            "type" : "array",
            "items" : {
                "type" : "string"
            }
        }
    }
}

Here's the Mapping template:

#set($inputRoot = $input.path('$'))
[
#foreach($question in $inputRoot) {
    "section_name" : "$question.section_name.S",
    "options" : [
    #foreach($items in $question.options.L) {
    [
        #foreach($item in $items.L) {
        "$item.S"
        }#if($foreach.hasNext),#end
        #end
    ]        
    }#if($foreach.hasNext),#end
    #end
    ]

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

#end
]

Although this syntax correctly maps the data it results in "options" being an empty array.

Without the "options" specified then my iOS app receives valid JSON. But when I try various syntaxes for "options" then I either get invalid JSON or an "Internal Service Error" and CloudWatch isn't much better offering Unable to transform response.

The options valid is populated with this content: {L=[{"L":[{"S":"1"},{"S":"Dr"}]},{"L":[{"S":"2"},{"S":"Mr"}]},{"L":[{"S":"3"},{"S":"Ms"}]},{"L":[{"S":"4"},{"S":"Mrs"}]},{"L":[{"S":"5"},{"S":"Prof."}]}]} which is provided by a Lambda function.

I can only conclude, at this point, that API Gateway VTL doesn't support nested arrays.

Carl
  • 2,896
  • 2
  • 32
  • 50

1 Answers1

4

AWS iOS SDK for Modelling doesn't support array of arrays.

You have to define a dictionary in between any nested arrays. So instead of array/object/array/array you slip in an extra "awshack" object: array/object/array/awshack-object/array

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "QuestionsModel",
"type": "array",
"items": {
    "type": "object",
    "properties": {
        "section_name": { "type": "string" },
        "options" : { "type" : "array",
                      "items" : {
                          "type" : "object",
                          "properties" : {
                              "awshack" : {
                                  "type" : "array",
                                  "items" : { "type" : "string" }
                              }
                          }
                    }

        }
    }
}
}

In the mapping template the "awshack" is slipped in outside the innermost loop.

#foreach($items in $question.options.L)
    {"awshack" : 
        [#foreach($item in $items.L)
            "$item.S"#if($foreach.hasNext),#end
        #end
    #if($foreach.hasNext),#end
]}#if($foreach.hasNext),#end
#end

Amazon confirms this limitation.

Carl
  • 2,896
  • 2
  • 32
  • 50