title: AWS Lambda python custom response encoding
body: <p>When you query data with your lambda function from dynamodb and there are binary types or decimal/number types in it my default setup below prompts with an JSONEncoding Error that he cannot deal with Binary or Decimal. I can work around with a small piece of code that I attach to <code>json.dumps(data, indent=2, cls=JSONEncoder)</code></p>
  
  <pre class="lang-py prettyprint-override"><code>class JSONEncoder(json.JSONEncoder):
      def default(self, o):
          if isinstance(o, decimal.Decimal):
              if o % 1 &gt; 0:
                  return float(o)
              else:
                  return int(o)
          return super(JSONEncoder, self).default(o)
  </code></pre>
  
  <p>But using <code>json.dumps()</code> in front of your <code>return</code> statement double json format the response and that leads to escaped signs. To repeat the problem just <code>return data</code> prompts with the mentioned error.</p>
  
  <p>How can I affect my <code>return</code> statement that converts to json?</p>
  
  <h2>UPDATE:</h2>
  
  <p>The problem is solved dirty by manually change the items with:
  </p>
  
  <pre><code>test = operations['Items'][0]
  test['id'] = float(test['id'])
  </code></pre>
  
  <p>But this seems messy.</p>