0

Using Flask, I've attempted to load a static JSON file using send_from_directory. From this I get a Response object. I cannot get this object in JSON format; however.

courses = send_from_directory("static/", "courses.json");
courses["math"] # not a JSON - cannot get math element from loaded courses
jsonify(courses) # Object of type Response is not JSON serializable

How would one go about converting a response into JSON format, then?

edit: To clarify - I'm not looking to return a file and a JSON. I am seeking to get a dict from a JSON file that is located within "/static" in the working directory.

Orange Receptacle
  • 1,173
  • 3
  • 19
  • 40

1 Answers1

0

try this:

import json

courses = send_from_directory("static/", "courses.json");

courses_dict = json.loads(courses)
print(courses_dict["math"])
Errol
  • 600
  • 4
  • 16