title: How to extract the json data without square brackets in python
body: <p>I suspect I am facing an issue because my json data is within square brackets ([]).
  I am processing pubsub data which is in below format.</p>
  <pre><code>[{&quot;ltime&quot;:&quot;2022-04-12T11:33:00.970Z&quot;,&quot;cnt&quot;:199,&quot;fname&quot;:&quot;MYFILENAME&quot;,&quot;data&quot;:[{&quot;NAME&quot;:&quot;N1&quot;,&quot;ID&quot;:11.4,&quot;DATE&quot;:&quot;2005-10-14 00:00:00&quot;},{&quot;NAME&quot;:&quot;M1&quot;,&quot;ID&quot;:25.0,&quot;DATE&quot;:&quot;2005-10-14 00:00:00&quot;}]
  </code></pre>
  <p>I am successfully processing/extracting all the fields except 'data'. I need to create a json file using the 'data' in a cloud storage.</p>
  <p>when I use <code>msg['data']</code> I am getting below,</p>
  <pre><code>[{&quot;NAME&quot;:&quot;N1&quot;,&quot;ID&quot;:11.4,&quot;DATE&quot;:&quot;2005-10-14 00:00:00&quot;},{&quot;NAME&quot;:&quot;M1&quot;,&quot;ID&quot;:25.0,&quot;DATE&quot;:&quot;2005-10-14 00:00:00&quot;}]
  </code></pre>
  <p>Sample code:</p>
  <pre><code>pubsub_msg = base64.b64decode(event['data']).decode('utf-8')
  pubsub_data = json.loads(pubsub_msg)
  
  json_file = pubsub_data['fname'] + '.json'
  json_content = pubsub_data['data']
  try:
      &lt;&lt; call function &gt;&gt;
  except Exception as e:
      &lt;&lt; Error &gt;&gt;
  </code></pre>
  <p>below is the error I am getting it.</p>
  <pre><code>2022-04-12T17:35:01.761Zmyapp-pipelineeopcm2kjno5h Error in uploading json document to gcs: [{&quot;NAME&quot;:&quot;N1&quot;,&quot;ID&quot;:11.4,&quot;DATE&quot;:&quot;2005-10-14 00:00:00&quot;},{&quot;NAME&quot;:&quot;M1&quot;,&quot;ID&quot;:25.0,&quot;DATE&quot;:&quot;2005-10-14 00:00:00&quot;}] could not be converted to bytes
  </code></pre>
  <p>I am not sure the issue is because of square brackets [].
  Correct me if I am wrong and please help to get the exact json data for creating a file.</p>