title: Accessing data in blob object from download_as_string in Python
body: <p>I am trying to access and modify data in a newline JSON file pulled from Google Cloud Storage in Google Cloud Functions. The results always show up as numbers despite that not being the data in the JSON. </p>
  
  <p>I see that download_as_string() for blob object returns Bytes (<a href="https://googleapis.github.io/google-cloud-python/latest/_modules/google/cloud/storage/blob.html#Blob.download_as_string" rel="noreferrer">https://googleapis.github.io/google-cloud-python/latest/_modules/google/cloud/storage/blob.html#Blob.download_as_string</a>) but in any references I see, everyone is able to access their data just fine.</p>
  
  <p>I am doing this in Cloud Functions but I think my question would apply in any GCP tool.</p>
  
  <p>My example below simply should load the newline JSON data, add it to a list, select the first two dictionary entries, convert back to newline JSON and output to JSON file on GCS. Samples, code, and bad output listed below.</p>
  
  <p><strong>Sample newline JSON input</strong></p>
  
  <pre><code>{"Website": "Google", "URL": "Google.com", "ID": 1}
  {"Website": "Bing", "URL": "Bing.com", "ID": 2}
  {"Website": "Yahoo", "URL": "Yahoo.com", "ID": 3}
  {"Website": "Yandex", "URL": "Yandex.com", "ID": 4}
  </code></pre>
  
  <p><strong>Code in Cloud Function</strong></p>
  
  <pre class="lang-py prettyprint-override"><code>import requests
  import json
  import csv
  from datetime import datetime, timedelta
  import sys
  from collections import OrderedDict
  import os
  import random
  
  from google.cloud import bigquery
  from google.cloud import storage
  
  def importData(request, execution):
      # Read the data from Google Cloud Storage
      read_storage_client = storage.Client()
  
      # Set buckets and filenames
      bucket_name = "sample_bucket"
      filename = 'sample_json_output.json'
  
      # get bucket with name
      bucket = read_storage_client.get_bucket('sample_bucket')
      # get bucket data as blob
      blob = bucket.get_blob('sample_json.json')
      # download as string
      json_data = blob.download_as_string()
  
      # create list 
      website_list = []
      for u,y in enumerate(json_data):
          website_list.append(y)
  
      # select first two
      website_list = website_list[0:2]
  
      # Create new-line JSON
      results_ready = '\n'.join(json.dumps(item) for item in website_list)
  
      # Write the data to Google Cloud Storage
      write_storage_client = storage.Client()
  
      write_storage_client.get_bucket(bucket_name) \
          .blob(filename) \
          .upload_from_string(results_ready)
  </code></pre>
  
  <p><strong>Current output in sample_json_output.json file</strong></p>
  
  <pre><code>123
  34
  </code></pre>
  
  <p><strong>Expected output</strong></p>
  
  <pre><code>{"Website": "Google", "URL": "Google.com", "ID": 1}
  {"Website": "Bing", "URL": "Bing.com", "ID": 2}
  </code></pre>
  
  <p><strong>Update 6/6: If I write a file straight from the <em>download_to_string</em> blob, then it writes the JSON file perfectly, but I need to access the contents prior.</strong></p>
  
  <pre class="lang-py prettyprint-override"><code>import requests
  import json
  import csv
  from datetime import datetime, timedelta
  import sys
  from collections import OrderedDict
  import os
  import random
  
  from google.cloud import bigquery
  from google.cloud import storage
  
  def importData(request, execution):
  
      # Read the data from Google Cloud Storage
      read_storage_client = storage.Client()
  
      # Set buckets and filenames
      bucket_name = "sample_bucket"
      filename = 'sample_json_output.json'
  
      # get bucket with name
      bucket = read_storage_client.get_bucket('sample_bucket')
  
      # get bucket data as blob
      blob = bucket.get_blob('sample_json.json')
  
      # convert to string
      json_data = blob.download_as_string()
  
  
      # Write the data to Google Cloud Storage
      write_storage_client = storage.Client()
  
      write_storage_client.get_bucket(bucket_name) \
          .blob(filename) \
          .upload_from_string(json_data)
  </code></pre>
  
  <p><strong>Update 6/6 Output</strong></p>
  
  <pre><code>{"Website": "Google", "URL": "Google.com", "ID": 1}
  {"Website": "Bing", "URL": "Bing.com", "ID": 2}
  {"Website": "Yahoo", "URL": "Yahoo.com", "ID": 3}
  {"Website": "Yandex", "URL": "Yandex.com", "ID": 4}
  </code></pre>