title: Converting a dataframe into JSON (in pyspark) and then selecting desired fields
body: <p>I'm new to Spark. I have a dataframe that contains the results of some analysis. I converted that dataframe into JSON so I could display it in a Flask App:</p>
  
  <pre><code>results = result.toJSON().collect()
  </code></pre>
  
  <p>An example entry in my json file is below. I then tried to run a for loop in order to get specific results:</p>
  
  <pre><code>{"userId":"1","systemId":"30","title":"interest"}
  
  for i in results:
      print i["userId"]
  </code></pre>
  
  <p>This doesn't work at all and I get errors such as: Python (json) : TypeError: expected string or buffer</p>
  
  <p>I used <code>json.dumps</code> and <code>json.loads</code> and still nothing - I keep on getting errors such as string indices must be integers, as well as the above error.</p>
  
  <p>I then tried this:</p>
  
  <pre><code>  print i[0]
  </code></pre>
  
  <p>This gave me the first character in the json "{" instead of the first line. I don't really know what to do, can anyone tell me where I'm going wrong?</p>
  
  <p>Many Thanks.</p>