title: API Gateway Mapping Template optional field
body: <p>I've been working with Mapping Templates on AWS API Gateway, in particular for DynamoDB integration. And I found very inconvenient to check against optional fields. For example I have a JSON payload like this:</p>
  
  <pre><code>{
      "optional_field": "abcd" 
  }
  </code></pre>
  
  <p>now to put it to the database I use a mapping like this:</p>
  
  <pre><code>#set($hasOptionalField = $input.path('$.optional_field') != "")
  {
      "TableName": "A_Table",
      "Item": {
          "id": {"S": "$context.requestId"}
  #if($hasOptionalField),
          "optional_field": {"S": "$input.path('$.optional_field')"}
  #end
      }
  }
  </code></pre>
  
  <p>According to <a href="http://velocity.apache.org/engine/devel/vtl-reference.html#properties" rel="nofollow noreferrer">Apache Velocity Reference</a> I should be able to use much simpler syntax do check for null, empty, false or zero and fallback automatically to some alternative value, something beautiful like this:</p>
  
  <pre><code>{
      "TableName": "A_Table",
      "Item": {
          "id": {"S": "$context.requestId"},
          "optional_field": {"S": "${input.path('$.optional_field')|'no_data'}"}
      }
  }
  </code></pre>
  
  <p>I could just leave it as is without any fallback, but DynamoDB API gives you an error if try to put empty string as an attribute value.</p>
  
  <p>It seems like API Gateway Mapping Templates does not 100% implement Apache Velocity specification?</p>