title: Pyramid rendered JSON Response returned as a string
body: <p>I'm using the pyramid web framework and writing some functions that receive and respond with JSON.</p>
  
  <p>Here is some code I've written that returns the files and directories from a given directory </p>
  
  <pre><code>@view_config(route_name='file', renderer='json')
  def file(request):
      values = request.json_body
      path = os.path.dirname(__file__) + '/files' + values['path']
      if os.path.isdir(path):
          files = [ f for f in os.listdir(path) if os.path.isfile(os.path.join(path,f)) ]
          dirs = [ f for f in os.listdir(path) if os.path.isdir(os.path.join(path,f)) ]
          if files is None:
              files = []
          if dirs is None:
              dirs = []
          response = dict()
          response['version']='1.0'
          response['files']=files
          response['directories']=dirs
          return response
      else:
          response = dict()
          response['version']='1.0'
          response['files']=[]
          response['directories']=[]
          return response
  
  @view_config(route_name='files', renderer='templates/filesTest.jinja2')
  def files(request):
      if 'form.submitted' in request.params:
          json_payload = json.dumps({'path':request.params['path']})
          headers = {'Content-Type':'application/json; charset=utf-8'}
          req = urllib2.Request(request.route_url('file'), json_payload, headers)
          resp = urllib2.urlopen(req)
          data = resp.read()
          return dict(dirs=[], files=[], saveURL = request.route_url('files'), pathDefault=request.params['path'])
      return dict(dirs=[], files=[], saveURL = request.route_url('files'), pathDefault='/')
  </code></pre>
  
  <p>I'm mainly having trouble with the files function. <code>type(data)</code> is returning <code>&lt;type 'str'&gt;</code>. Sending the string to my template displays <code>{"files": ["file1.jpg", "file2.png"], "version": "1.0", "directories": ["Directory1"]}</code></p>
  
  <p>Does anyone know why I'm getting a string result?</p>