title: Dynamo DB scan query to obtain output file in JSON format
body: <p>I am quite new to Dynamo DB using boto3. I would like to: obtain a scan of all the rows in Dynamo DB and store it in <code>JSON</code> format, in a file, for additional data processing.</p>
  
  <p>I am presently using the script shown below to fetch the details (pagination will be involved) :</p>
  
  <pre><code>from __future__ import print_function # Python 2/3 compatibility
  import boto3
  import json
  import decimal
  from boto3.dynamodb.conditions import Key, Attr
  
  # Helper class to convert a DynamoDB item to JSON.
  class DecimalEncoder(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(DecimalEncoder, self).default(o)
  
  dynamodb = boto3.resource('dynamodb')
  
  table = dynamodb.Table('Movies')
  
  #fe = Key('year').between(1951, 1964)
  pe = "#yr, title, info.rating"
  # Expression Attribute Names for Projection Expression only.
  ean = { "#yr": "year", }
  esk = None
  
  
  response = table.scan(
  #    FilterExpression=fe,
      ProjectionExpression=pe,
      ExpressionAttributeNames=ean
      )
  
  for i in response['Items']:
      print(json.dumps(i, cls=DecimalEncoder)) 
  
  while 'LastEvaluatedKey' in response:
      response = table.scan(
          ProjectionExpression=pe,
  #        FilterExpression=fe,
          ExpressionAttributeNames= ean,
          ExclusiveStartKey=response['LastEvaluatedKey']
          )
  
      for i in response['Items']:
          print(json.dumps(i, cls=DecimalEncoder),)
  </code></pre>
  
  <p>This gives me sample output of 5000 rows: </p>
  
  <pre><code>{"info": {"rating": 6.5}, "year": 2004, "title": "The Polar Express"}
  {"info": {"rating": 5.7}, "year": 2004, "title": "The Prince &amp; Me"}
  {"info": {"rating": 5.3}, "year": 2004, "title": "The Princess Diaries 2: Royal Engagement"}
  {"info": {"rating": 6.3}, "year": 2004, "title": "The Punisher"}
  {"info": {"rating": 6.8}, "year": 2004, "title": "The SpongeBob SquarePants Movie"}
  </code></pre>
  
  <p>I am unable to get the output in the desired format (as shown below). I am expecting a file here. </p>
  
  <pre><code>[
      {"info": {"rating": 6.5}, "year": 2004, "title": "The Polar Express"},
      {"info": {"rating": 5.7}, "year": 2004, "title": "The Prince &amp; Me"},
      {"info": {"rating": 5.3}, "year": 2004, "title": "The Princess Diaries 2: Royal Engagement"},
      {"info": {"rating": 6.3}, "year": 2004, "title": "The Punisher"},
      {"info": {"rating": 6.8}, "year": 2004, "title": "The SpongeBob SquarePants Movie"}
  ]
  </code></pre>
  
  <p>Could anyone please provide me some hints or pointers on how to investigate this further?</p>