title: Apache-Beam + Python: Writing JSON (or dictionaries) strings to output file
body: <p>I am trying to use a Beam pipeline in order to apply the SequenceMatcher function to a ton of words. I (hopefully) have figured everything out except the WriteToText part.</p>
  
  <p>I have defined a custom ParDo (hereby called ProcessDataDoFn) that takes the main_input and the side_input, process them and output dictionaries like this one </p>
  
  <pre><code>{u'key': (u'string', float)}
  </code></pre>
  
  <p>My pipeline is quite simple</p>
  
  <pre><code>class ProcessDataDoFn(beam.DoFn):
      def process(self, element, side_input):
  
      ... Series of operations ...
  
      return output_dictionary
  
  with beam.Pipeline(options=options) as p:
  
      # Main input
      main_input = p | 'ReadMainInput' &gt;&gt; beam.io.Read(
          beam.io.BigQuerySource(
              query=CUSTOM_SQL,
              use_standard_sql=True
          ))
  
      # Side input
      side_input = p | 'ReadSideInput' &gt;&gt; beam.io.Read(
          beam.io.BigQuerySource(
              project=PROJECT_ID,
              dataset=DATASET,
              table=TABLE
          ))
  
      output = (
          main_input
          | 'ProcessData' &gt;&gt; beam.ParDo(
              ProcessDataDoFn(),
              side_input=beam.pvalue.AsList(side_input))
          | 'WriteOutput' &gt;&gt; beam.io.WriteToText(GCS_BUCKET)
      )
  </code></pre>
  
  <p>Now the problem is that if I leave the pipeline like this it only output the key of the output_dictionary. If I change the return of ProcessDataDoFn to json.dumps(ouput_dictionary), The Json is written correctly but like this</p>
  
  <pre><code>{
  '
  k
  e
  y
  '
  
  :
  
  [
  '
  s
  t
  r
  i
  n
  g
  '
  
  ,
  
  f
  l
  o
  a
  t
  ]
  </code></pre>
  
  <p>How can I correctly output the results?</p>