1

In my application, there is an endpoint that sends me the raw contents of a Yaml file in response to an AJAX call. I want to display them as they are in UI. The console throws an obvious error, which is for invalid JSON. How would I do it?

Update:

This is the snippet used for reading the file and sending the response.

filename = __file__ # Select your file here.                                
wrapper = FileWrapper(file(filename))
response = HttpResponse(wrapper, content_type='text/plain')
response['Content-Length'] = os.path.getsize(filename)
return response

Is there a way I could form a dictionary there with the contents of the file and then send the response?

Rutwick Gangurde
  • 4,772
  • 11
  • 53
  • 87

1 Answers1

0

From server, use jsonify on the raw content, pack it and ship it over to client.

repacked_json = json.dumps(raw_yaml_data) 
json_obj = json.loads(repacked_json)
return jsonify(result = json_obj)
Sidmeister
  • 856
  • 2
  • 14
  • 27