title: Creating Json Output Boto3
body: <p>I have the code below:</p>
  
  <pre><code>import boto3
  import datetime
  import json
  
  now = datetime.datetime.now()
  
  cw = boto3.client('cloudwatch', region_name='sa-east-1')
  s3client = boto3.client('s3')
  
  # Get a list of all buckets
  allbuckets = s3client.list_buckets()
  
  # Iterate through each bucket
  for bucket in allbuckets['Buckets']:
      # For each bucket item, look up the cooresponding metrics from CloudWatch
      response = cw.get_metric_statistics(Namespace='AWS/S3',
                                          MetricName='BucketSizeBytes',
                                          Dimensions=[
                                              {'Name': 'BucketName', 'Value': bucket['Name']},
                                              {'Name': 'StorageType', 'Value': 'StandardStorage'},
                                          ],
                                          Statistics=['Average'],
                                          Period=3600,
                                          StartTime=(now-datetime.timedelta(days=2)).isoformat(),
                                          EndTime=now.isoformat()
                                          )
      for item in response["Datapoints"]:
              data = {}
              data['data'] = []
              data['data'].append ({'#BUCKET_NAME': bucket["Name"]})
              json_str = json.dumps(data)
              print json_str
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>{"data": [{"#BUCKET_NAME": "bucket1"}]}
  {"data": [{"#BUCKET_NAME": "bucket2"}]}
  {"data": [{"#BUCKET_NAME": "bucket3"}]}
  {"data": [{"#BUCKET_NAME": "bucket4"}]}
  </code></pre>
  
  <p>But i need the output in the following format:</p>
  
  <pre><code>    {"data":[{"{#BUCKET_NAME}":"bucket1"},{"{#BUCKET_NAME}":"bucket2"},
               {"{#BUCKET_NAME}":"bucket3"},{"{#BUCKET_NAME}":"bucket4"}]}
  </code></pre>
  
  <p>Where i am doing wrong ? </p>